Okay, I must get the latest compiler then. Funny, I have compiled my version only a few…
Markku Niskanen wrote 8 lines
It was changed/fixed on friday only.
Michael.

Mailing lists / lazarus / 1999-08
5 messages · 3 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Okay, I must get the latest compiler then. Funny, I have compiled my version only a few…
It was changed/fixed on friday only.
Michael.
I have done a lot of testing with the heap functions and now I suspect I have found a…
1) There recently was a bug in the delphi-like memory allocator;
this was solved.2) the output of your program is the following:
home: >testm
Bytes to reserve: 1000
Mem : 262112
After StrAlloc : 261104(-1008)
After strPcopy : 261104(-1008)
After strDispose: 262112(-0)
Bytes to reserve: 100
Mem : 262112
After StrAlloc : 262000(-112)
After strPcopy : 262000(-112)
After strDispose: 262112(-0)
Bytes to reserve: 0
Is this now correct or wrong ? Seems OK to me ?
The fact that it reserves 8 bytes more is a consequence of the old-style calls in sysutils, combined with the new delphi-style memory manager automatically used if you use delphi or objfpc mode. This will be again reduced to 4 ASAP.
Michael.
you wroteIs this now correct or wrong ? Seems OK to me ?
Okay, I must get the latest compiler then.
Funny, I have compiled my version only a
few days ago, must have messed up with
the CVS somehow.
Thanks, I'll do my best to continue with
my excavations :-)
Markku
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.It was changed/fixed on friday only. Michael.
you wroteIt was changed/fixed on friday only.
Now everything seems to work just fine,
thank you. Back to work!
Markku