From: Robert A Duff on
Gene <gene.ressler(a)gmail.com> writes:

> Your code thrashes the heap pretty hard. Containers doubles the size
> of the vector's internal array each time it runs out. So the 2Gb
> request means 1Gb is already in use. Dont' know about your malloc(),
> but it's easy to see that a 1Gb allocated block in a 4Gb arena can
> preclude a further 2Gb allocation.

Good point. Note that when you grow from 1GB to 2GB, you have both
allocated for the time it takes to copy the data over. That won't work
if the user part of the address space is limited to 3GB. Some part of
that 3GB is used for other stuff. Plus the heap might well be
fragmented.

A better test of how much you can allocate would allocate a whole bunch
of smaller objects.

- Bob
From: anon on
Adjust your heap size in the linking phase.

In <g3qc68$5a5$1(a)aioe.org>, Dennis Hoppe <dennis.hoppe(a)hoppinet.de> writes:
>Hi,
>
>my machine has 4 GB of RAM and I am wondering, why I can't use
>at least 2 or 3 GBytes to run an Ada program. It seems, that my
>Ada Compiler (Gnat 4.4.0) limit the memory to 2 GB per default.
>Is it possible to allocate more than 2 GB?
>
>Here is a simple example of an "evil" vector, that gains
>more memory in each pass. The program terminates exactly at
>1024 MB of used Heap memory.
>
>
>with Ada.Containers.Vectors;
>
>procedure Heap is
> package Generic_Vector is new Ada.Containers.Vectors
> (Element_Type => Integer, Index_Type => Natural);
>
> Evil_Vector : Generic_Vector.Vector;
>begin -- Heap
> loop
> Generic_Vector.Append (Evil_Vector, Integer'Last);
> end loop;
>end Heap;
>
>
>heap(6374) malloc: *** mmap(size=2147487744) failed (error code=12)
>*** error: can't allocate region
>*** set a breakpoint in malloc_error_break to debug
>
>raised STORAGE_ERROR : heap exhausted
>
>
>I could not find a suitable Compiler switch or a parameter, that
>can be set for the operating system (linux). "ulimit -v" is already
>set to unlimited.
>
>"gnatmem" reports, that my water mark with 1024 MB is reached, but
>the final water mark is, needless to say, higher.
>
>
>Best regards,
> Dennis Hoppe

From: Peter Schildmann on
Dennis Hoppe schrieb:
> Here is a simple example of an "evil" vector, that gains
> more memory in each pass. The program terminates exactly at
> 1024 MB of used Heap memory.

I was able to allocate much more memory with the following
test program on a 64-bit machine running Debian Etch
(tested with gcc 4.1.2 and gcc 4.3.1).

- Peter


with Ada.Text_IO;
with Ada.Containers;
with Ada.Containers.Vectors;

procedure Heap is

subtype Element_Type is Long_Integer; -- 8 bytes

Element_Size : constant := Element_Type'Size / Standard'Storage_Unit;

subtype Index_Type is Natural
range 0 .. 6 * 1024 * 1024 * 1024 / Element_Size - 1; -- 6GB!

package Cnt_IO is new Ada.Text_IO.Integer_IO
(Ada.Containers.Count_Type);

package Generic_Vector is new Ada.Containers.Vectors
(Element_Type => Element_Type, Index_Type => Index_Type);

Evil_Vector : Generic_Vector.Vector;

begin

for N in Index_Type'Range loop
Generic_Vector.Append (Evil_Vector, Long_Integer (N));
end loop;

Ada.Text_IO.Put ("Length: ");
Cnt_IO.Put (Generic_Vector.Length (Evil_Vector));

Ada.Text_IO.New_Line;

Ada.Text_IO.Put ("Capacity: ");
Cnt_IO.Put (Generic_Vector.Capacity (Evil_Vector));

end Heap;
From: Dennis Hoppe on
Hi Peter,

unfortunately, your code provided below produces the same behaviour:

heap(9830) malloc: *** mmap(size=2147487744) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

raised STORAGE_ERROR : heap exhausted


Another point is, that I run actually a 64 bit OS (Mac OS X 10.5),
so I tried to compile the source code explicitly with the 64 bit flag

gcc -gnato -m64 -c heap.adb,

but I got the following errors:

heap.adb:10:04: instantiation error at a-convec.ads:330
heap.adb:10:04: alignment for "Vectort31b" must be at least 8
heap.adb:10:04: instantiation error at a-convec.ads:330
heap.adb:10:04: alignment for "Vectorb36b" must be at least 8

Line 10 is:

package Generic_Vector is new Ada.Containers.Vectors
(Element_Type => Integer, Index_Type => Natural);


Is it possible, that this flag (-m64) is actually not supported
for my system/compiler?

gcc (GCC) 4.4.0 20080314 (experimental) [trunk revision 133226]
GNAT 4.4.0 20080314 (experimental) [trunk revision 133226]
Darwin Kernel 9.3.0 root:xnu-1228.5.18~1/RELEASE_I386 i386


Thank you all,
Dennis


Peter Schildmann wrote:
> Dennis Hoppe schrieb:
>> loop
>> Generic_Vector.Append (Evil_Vector, Integer'Last);
>> end loop;
>
> It's not a good idea to use the STORAGE_ERROR exception
> to terminate an endless loop.
>
> This should work:
>
> with Ada.Text_IO;
> with Ada.Containers;
> with Ada.Containers.Vectors;
>
> procedure Heap is
>
> package Cnt_IO is new Ada.Text_IO.Integer_IO
> (Ada.Containers.Count_Type);
>
> package Generic_Vector is new Ada.Containers.Vectors
> (Element_Type => Integer, Index_Type => Natural);
>
> Evil_Vector : Generic_Vector.Vector;
>
> Size : constant := Integer'Size / Standard'Storage_Unit;
>
> begin
>
> for N in 0 .. Natural'Last / Size loop
> Generic_Vector.Append (Evil_Vector, N);
> end loop;
>
> Cnt_IO.Put (Generic_Vector.Capacity (Evil_Vector));
>
> end Heap;
>
>
> - Peter
From: Dennis Hoppe on
Hi Peter,

Peter Schildmann wrote:
> I was able to allocate much more memory with the following
> test program on a 64-bit machine running Debian Etch
> (tested with gcc 4.1.2 and gcc 4.3.1).
> [code snippet]

The same code runs on machine out of memory at 1024 MB.
I thought, my system is 64 bit (Mac OS X 10.5), hmm.
With the gcc flag -m64 I get the following error while compiling:

heap.adb:17:04: instantiation error at a-convec.ads:330
heap.adb:17:04: alignment for "Vectort31b" must be at least 8
heap.adb:17:04: instantiation error at a-convec.ads:330
heap.adb:17:04: alignment for "Vectorb36b" must be at least 8


Best regards,
Dennis
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: GNAT.Serial_Communications ?
Next: Larger matrices