swap arrays between your appz with PBOSL_GlobalSharedMemory

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

swap arrays between your appz with PBOSL_GlobalSharedMemory

Post by Rings »

its a bit tricky, need some inlineasm (for patching the array-pointer),
but works okay for me:

Code: Select all

; Tricky, uses a inline-patch
;
; written by Siegfried Rings in 2005
;
; To test this, start it twice
;
; Remark: If you use the debugger, an array out of bounds can happen
;     Solution: dim the arry big enough


Dim MyArray.f(0) ;Dim of an array

GBName.s="JoRo1"



xMax=4096
yMax=4096
Bytesize=4 ;4 bytes=1 float
GBSize=xMax*yMax * Bytesize

GBPointer=PBOSL_AllocateMemoryGlobal(GBName,GBSize)

If GBPointer

 ;these 2 line maps the array to global usage :)
 !MOV eax,dword[v_GBPointer] ;Load Memorypointer into  eax
 !MOV dword [a_MyArray],eax ;copy Pointer 2 Array
 

 ;Writing
 For X=0 To 9
  MyArray(X)=MyArray(X)+0.5*X +0.25
 Next X 

 ;Reading
 sdummy.s=""
 For X=0 To 9
  sdummy.s=sdummy.s+ StrF( MyArray(X)) + Chr(13)
 Next X 

 MessageRequester("Info",sdummy,0)
 
 PBOSL_FreeMemoryGlobal(GBPointer)
EndIf
SPAMINATOR NR.1