to my surprise i found the functions NEW and DISPOSE sort of hidden in the build in functions instead of beeing part of the memmanager library, anyway i started to play but failed so far to access the contents of a NEWed recordvariable, i can see in the debugger that the pointer gets assigned a value but that is all. It would also be usefull if we could inspect the contents of such dynamic variable in the debugger. Are there any examples of how to use this ?
Looking at the assembly i have the impression something is wrong with the offset inside the recordvariable for a start
memmanager
memmanager
Au royaume des aveugles, les borgnes sont rois.
Re: memmanager
seems i was a bit hasty here, seems to work ok but as i currently cannot inspect the record on the heap mislead myself, that part of the question remains : how to access in the debugger dynamic variables ?
Au royaume des aveugles, les borgnes sont rois.
Re: memmanager
however i found some other issue : after disposing a variable the function MM_TotalFreeMemSize seems not to report correctly, the pointer as such indeed returns to NIL but the allocated memory seems gone forever. This seems identical after a call of FreeMem which i was hoping anyway not to need if we have a properly working DISPOSE
Au royaume des aveugles, les borgnes sont rois.
Re: memmanager
ok, here a little testprogram, i have commented the behaviour as i see it, please have a look at this, most seems to work but there are a few strange loose ends here, i will try to run this on hardware later .
Code: Select all
program dyn_var_test;
// deliberatly set heapsize to 1000 in the project-editor, this will NOT be enough for 2 recordvariables of the used type
// this has only been tested in software debugger currently, perhaps behaves different on hardware
const maxpar = 10;
parlength = 10;
Type Tpars = Record // Datatype For Cmd Interpreter
Pars : Array[Maxpar] Of String[Parlength];
Param,
Character : Byte;
End;
var outstr : string[64];
dcounter : dword;
i : byte;
dyn_var : ^array[5] of tpars;
j : dword;
begin
j := MM_TotalFreeMemSize; // seems ok, heap not yet initialised
MM_Init(); // now 1000 bytes available
j := MM_TotalFreeMemSize;
new(dyn_var); // here 560 bytes are claimed on the heap
j := MM_TotalFreeMemSize; // so only 440 left free
new(dyn_var); // as this NEW fails the pointer gets assigned the value NIL
j := MM_TotalFreeMemSize; // and nothing changes here
with dyn_var^[3] do // this is strange however, allthough the pointer is NIL, it points to something
begin
param:= 42;
pars[7] := 'yellow';
pars[2] := pars[7];
pars[2][6] := 'x';
end;
i := dyn_var^[3].param; // this value is retrieved from that something
nop;
i := 0; // cleared ( without the nop in between is not updated by debugger
nop;
outstr := dyn_var^[3].pars[2]; // allthough the pointer is still NIL i retrieve the values from the record
dispose(dyn_var); // in fact nothing left to dispose but i just wanted to check
with dyn_var^[3] do // again, assignment of values go somewhere
begin
param:= 42;
pars[7] := 'orange';
pars[2] := pars[7];
pars[2][6] := 'x';
end;
i := dyn_var^[3].param;
outstr := dyn_var^[3].pars[2]; // and these values are stiull there
MM_Init(); // seems to work only first time, now changes nothing
j := MM_LargestFreeMemBlock; // seems not to have worked
j := MM_LargestFreeMemBlock; // and all of a sudden reports 1000 again
end.
Au royaume des aveugles, les borgnes sont rois.
Re: memmanager
ok, did the test on hardware and feel some shame, it works as it should, the problems i reported seem only to exist in the software-debugger I am confident these issues will be solved in the future.
It is obvious that we can do stupid things when working with dynamic vars but the compiler is not to blame for our mistakes ( like assigning some value to a field of a NIL pointer) on the hardware , after the DISPOSE the correct heapsize is reported. This will open new doors for sure, thanks ME!
It is obvious that we can do stupid things when working with dynamic vars but the compiler is not to blame for our mistakes ( like assigning some value to a field of a NIL pointer) on the hardware , after the DISPOSE the correct heapsize is reported. This will open new doors for sure, thanks ME!
Au royaume des aveugles, les borgnes sont rois.