I just made 2 functions to Put an Image into shared memory and Read it from another app, without any files being used.
Just run the example twice, for the first press "P" and for the second (while first is still running) press "R" and then the same random image should appear on both screens =)
I quickly commented the example code, isnt the best commentation
oh and THIS NEEDS matrix1util (like all of my snippets
)
//setup
Sync on
Repeat : cls
Print "[P]ut File into shared memory"
Print "[R]ead File from shared memory"
Sync : Until fast lower$(Inkey$())="p" or fast lower$(Inkey$())="r"
If inkey$()="p" then Put=1
//Prepare the mutex
Make Sysobj Mutex 1,"ShMemM"
If Put
// Put-Part >>>
//make a random image, size doesnt mattter
For x=0 to 50
For y=0 to 50
Dot x,y,rgb(rnd(255),rnd(255),rnd(255))
Next
Next
Get Image 1,0,0,50,50
Cls
//lock the mutex
Lock Sysobj 1
//Map the image to the shared memory
MapImage(1,1)
//free the mutex so image can be read
Unlock Sysobj 1
//Wait for image to be locked and unlocked again
While Try Lock Sysobj(1) : Unlock Sysobj 1 : Endwhile
Wait 10
Repeat : Until Try Lock Sysobj(1)
//and delete the bank
Delete Bank 1
//<<<
Else
// Get-Part >>>
// wait until mutex is free and then lock it
Repeat : Until Try Lock Sysobj(1)
// read image from shared memory
ReadMapImage(1,1)
//release mutex so bank can be deleted by 'Put'-ter
Unlock Sysobj 1
//and delete the bank
Delete Bank 1
//<<<
Endif
//BOTH:
Paste Image 1,0,0,1
Sync : Sync
Wait Key
end
Function MapImage(n,m)
Paste Image n,0,0,1
Map Shared Mem To Bank "ShMem",m,(Image width(n)+1)*(image height(n)+1)*11+4
Write Bank Dword m,0,(Image width(n)+1)*(image height(n)+1)*11
P=3
For x=0 to image width(n)
for y=0 to image height(n)
c=Point(x,y)
Write Bank Dword m,P,x
Write Bank Dword m,P+4,Y
Write Bank Byte m,P+8,RGBR(c)
Write Bank Byte m,P+9,RGBG(c)
Write Bank Byte m,P+10,RGBB(c)
Inc P,11
Next
next
Endfunction
Function ReadMapImage(n,m)
Map Shared Mem To Bank "ShMem",m,1
S=Bank Dword(m,0)
P=3
Print S : Sync : Sync
Repeat
If ((P-3) mod 11)=0 or ((P-3)=0)
X=Bank Dword(m,P)
Y=Bank Dword(m,P+4)
Dot X,Y,Rgb(Bank Byte(m,P+8),Bank Byte(m,P+9),Bank Byte(m,P+10))
Endif
Inc P,11
Until P>S
Get Image n,0,0,X,Y,1
Endfunction
anyways i dont know if this is faster/slower/easier/harder than using a temporary file, but now i know all about shared memory and mutex