[lazarus] Pattern found!

Markku Niskanen markku.niskanen at laatumikro.fi
Sun Aug 22 05:31:24 EDT 1999


I have done a lot of testing with the heap functions and now I suspect
I have found a pattern in the getmem/StrAlloc and Freemem/StrDispose
problems.

Just run the following code and reserve heap memory
starting from 100 bytes and up. You can comment/uncomment
the Getmem/StrAlloc and Freemem/StrDispose lines to
check both pairs of memory functions.

I get four values with a memory leak of 4 bytes and four values
with zero memory leak. Has this something to do with the 64-byte
allocation alignment or what?

As for StrPcopy() there is an additional memory loss of 8 bytes
each the function is called and it follows the same pattern as the
rest of the behaviour.

The GetMem/Freemem works in Turbo Pascal, at least.

I have no idea how to correct the problem, maybe it is in the ASM part
of FPC.

-------------- clip ---------------------
program memtest;

uses sysutils;

var pStr: Pchar;
 st  : String;
 Bytes: Integer;
 BytesLost: LongInt;
 Free0,Free1,Free2,Free3: LongInt;

begin
    repeat
      Write( 'Bytes to reserve: ');
      Readln(Bytes);
      If Bytes = 0 then exit;
      St := '12345678901234567890';

      Free0 := Memavail();
      Writeln('Mem             : ',memavail());
      pStr := StrAlloc(bytes);
      //GetMem(pStr,Bytes);

      Free1 := Memavail();
      Writeln('After StrAlloc  : ',memavail(),'(-',Free0-Free1,')');
      // strPcopy(pStr,st); { this adds more problems if uncommented}

      Free2 := MemAvail();
      Writeln('After strPcopy  : ',memavail(),'(-',Free0-Free2,')');
      StrDispose(pStr);
      //FreeMem(pStr,Bytes);

      Free3 := MemAvail();
      Writeln('After strDispose: ',memavail(),'(-',Free0-Free3,')')

    until false;
end.





-- 
markku.niskanen at laatumikro.fi






More information about the Lazarus mailing list