I need to allocate some memory inside a procedure and then return a pointer to it from the procedure, after some experimentation I arrived at these two methods:
Code: Select all
Procedure.i AllocateSomeMem()
*Mem = AllocateMemory(1024)
ProcedureReturn *Mem
EndProcedure
Procedure AllocateOtherMem(*Pointer)
PokeI(*Pointer, AllocateMemory(1024))
EndProcedure
*MyPointer = #Null
AllocateOtherMem(@*MyPointer);pointer to pointer?
PokeS(*MyPointer, "other text here")
OtherText.s = PeekS(*MyPointer)
Debug OtherText
FreeMemory(*MyPointer)
*MyMem = AllocateSomeMem()
PokeS(*MyMem, "some text here")
Text.s = PeekS(*MyMem)
Debug Text
FreeMemory(*MyMem)
Thanks!