Re: GC performance - GC fragility



Just an example (for discussion):


var i, current : cardinal;
p, oldp : pointer;

const alloc = 65538;

begin
oldp := nil;
current := 0;

try
for I := 1 to 10000 do begin
p := AllocMem(i * alloc); current := current + i * alloc;
AllocMem(alloc); current := current + alloc;
FreeMem(oldp); current := current - ((i - 1)* alloc);
oldp := p;
end;

except
Writeln(current);
end;
ReadLn;

end.



This sample throws an exception at 934,702,956 bytes on my computer.
I can allocate nearly the double size with a single call to AllocMem.

Either I have written the sample wrong, could be for sure, or the allocation granularity and overhead for heap management are > 100% of the data itself, or - what I assume - the heap is fragmented.

While I wouldn't call this a practice sample, it's still a sample that virtual memory can't move and fix the fragmentation holes.
If my sample isn't wrong ;-).

Andre
.