Silvio a Beccara wrote:
thanks for the hints. I tried to compile and run your program, and I get a very similar result:
[...] allocated 2105834625 bytes allocated 2122416000 bytes allocated 2138997375 bytes ./heaptest: value out of range (error #300 at 8049dbc)
That's no memory allocation error, but a range-check error. The computed size (next would be 130 * 255 * 255 * 255) doesn't fit in a 32 bit signed integer anymore. If you want to allocate more than 2 GB in a single allocation (which was not your original request), you could try to use an unsigned type (Cardinal or perhaps better SizeType). However, I've never tested this, so there may be RTS or libc issues.
program heaptest; var i: integer; buf: pointer; siz: cardinal;
begin for i := 1 to 255 do begin siz := i * 255 * 255 * 255; getmem( buf, siz); writeln("allocated ", siz," bytes"); freemem( buf ); end; end.
The output was: [..] allocated 1989765000 bytes allocated 2006346375 bytes allocated 2022927750 bytes heaptest: out of heap when allocating 2039509125 bytes (error #853 at 8049e61)
Frank