Page 1 of 1

MemoryAllocation

Posted: Wed Oct 27, 2004 6:13 pm
by Andras
Hi, I use the following code to indirectly be able to pass a structure as a ProcedureReturn:


Structure MYSTRUC
x.f
y.f
EndStructure

Procedure.l Something()
*out.mystruc=AllocateMemory(SizeOf(mystruc))
*out\x=0.5
*out\y=1.25
ProcedureReturn *out
EndProcedure

CopyMemory(something(),test.mystruc,SizeOf(mystruc))

Debug test\x
Debug test\y


I'm wondering, if the allocated memory will be discarded by PureBasic (since it is now linked with 'test'), or if I have to do a "FreeMemory()".

Posted: Wed Oct 27, 2004 6:52 pm
by Manolo
This is more apropiate:

Code: Select all

Structure MYSTRUC 
x.f 
y.f 
EndStructure 

Procedure.l Something(*MYSTRUC.mystruc) 
*mystruc\x=0.5 
*mystruc\y=1.25 
ProcedureReturn  
EndProcedure 

Something(@test.MYSTRUC) 

Debug test\x 
Debug test\y 

Manolo