memmanager

Beta Testing discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

memmanager

#1 Post by jpc » 08 Feb 2012 15:31

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
Au royaume des aveugles, les borgnes sont rois.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: memmanager

#2 Post by jpc » 08 Feb 2012 15:47

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.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: memmanager

#3 Post by jpc » 08 Feb 2012 16:29

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.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: memmanager

#4 Post by jpc » 08 Feb 2012 17:14

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.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: memmanager

#5 Post by jpc » 08 Feb 2012 21:20

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 :oops: 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!
Au royaume des aveugles, les borgnes sont rois.

Post Reply

Return to “mikroPascal PRO for PIC32 Beta Testing”