Heap dimensions

Frank Heckenbach ih8mj at fjf.gnu.de
Mon Jul 25 19:31:34 CEST 2005


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

-- 
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/, 7977168E
GPC To-Do list, latest features, fixed bugs:
http://www.gnu-pascal.de/todo.html
GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE  D101 CD02 4C9D 0FE0 E5E8




More information about the Gpc mailing list