Originally Posted by
riwu
The data at the address of the heap might still be replaced after the array variable goes out of scope? (since having a pointer to it does not seem to constitute a proper reference requiring the program to continue reserving that memory for the variable)
So you'd have to allocate it globally? (eg. global var)
You can't alloc dynamic arrays locally, they will get cleaned up by Lape/FPC once you exit the function or once ref-count is 0, depending on what happens first.
You can however allocate your own data on the heap:
Simba Code:
type PInt32 = ^Int32;
function AllocThingy(): PInt32;
begin
ReallocMem(Result, SizeOf(Int32)*2);
MemMove([123,999][0], Result^, SizeOf(Int32)*2);
end;
var
p: Pointer;
x: Array of String;
begin
p := AllocThingy();
SetLength(x, 5); //some irrelevant array operation
WriteLn(PInt32(p)^); //prints 123
WriteLn(PInt32(p+4)^); //prints 999
FreeMem(p); //you have to free it yourself now..
end.