comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Increasing GNAT's heap
Date: Tue, 12 Nov 2013 20:30:41 +0100
Date: 2013-11-12T20:30:00+01:00	[thread overview]
Message-ID: <528281b8$0$9523$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <c9q64ds05sxz.1u5sw2krup9r1.dlg@40tude.net>

On 12.11.13 15:00, Dmitry A. Kazakov wrote:
> On Tue, 12 Nov 2013 14:26:42 +0100, Georg Bauhaus wrote:
> 
>> On 12.11.13 12:09, Dmitry A. Kazakov wrote:
>>> Does anybody know a way to increase the heap size available for GNAT? It
>>> crashes with famous GNAT BUG DETECTED, Storage_Error heap exhausted.
>>
>> Do ulimit values have any effect?
> 
> $ ulimit
> unlimited


FWIW, I am finding it difficult to trigger something beyond
"Storage_Error heap exhausted" (no bug, i.e.); SE seems kind
of expected for some amounts of memory requested. The program below
tries to make the memory manager commit, by forcing random inits
of the memory at random positions. The program runs quite
a while before either me interrupting it at 2**34 storage elements
(Mac OS X 10.7.5), or some Linux VMs duly reporting STORAGE_ERROR
while processing the memory for 2**32.

Both systems are 64 bit, though, so I can't tell what 32 bit gives as
results. I'm curious. Does this trigger a bug box in your system?
(size_t and others are there for hysteric raisins of comparison.)


with System.Storage_Elements;  use System.Storage_Elements;
with Ada.Unchecked_Deallocation;
with Ada.Numerics.Discrete_Random, Ada.Numerics.Elementary_Functions;
with Ada.Text_IO;

procedure Alloc_Ada
is
   --  powers of 2, for growing allocated sizes:
   Small : constant := 16;
   Large : constant := 40;

   type Void_Ptr is access Storage_Array;
   subtype size_t is Storage_Offset;
   package Size_T_IO is new Ada.Text_IO.Integer_IO (size_t);
   use Size_T_IO, Ada.Text_IO;

   procedure Init (Object : Void_Ptr; Acc : out Storage_Element);
   --  Initialize some of Object with random data. Place something
   --  almost anywhere in the allocated area, assuming that doing so
   --  will require commits.

   procedure Free is
     new Ada.Unchecked_Deallocation (Storage_Array, Void_Ptr);

   procedure Init (Object : Void_Ptr; Acc : out Storage_Element) is
      subtype Places is Storage_Offset range 0 .. Object'Length - 1;
      package Arb is new Ada.Numerics.Discrete_Random (Storage_Element);
      package Pos is new Ada.Numerics.Discrete_Random (Places);
      package Math renames Ada.Numerics.Elementary_Functions;
      G : Arb.Generator;
      P : Pos.Generator;
      Offset, Previous_Offset : Storage_Offset := 0;
      No_Of_Inits : constant Natural :=
        2**(Natural (Math.Log (Float (Object'Length), 2.0))
              -
            (Small - 4));
   begin
      Arb.Reset (G); Pos.Reset (P);
      Acc := 0;
      for Run in 1 .. No_Of_Inits loop
         Previous_Offset := Offset;
         Offset := Pos.Random (P);
         Object (Offset) := Arb.Random (G);
         Acc := Acc / 2
           + (Object (Previous_Offset) + Object (Offset)) / 4;
      end loop;
   end Init;

   Buffer : Void_Ptr;
   Kept : Storage_Element;

begin
   for Power in size_t range Small .. Large loop
      Put ("At "); Put (Power);
      Put (" ("); Put (2**Natural (Power)); Put (")");

      Buffer := new Storage_Array (0 .. 2**Natural (Power));
      Init (Buffer, Acc => Kept);

      Put_Line (Storage_Element'Image (Kept));

      Free (Buffer);
   end loop;
end Alloc_Ada;

  parent reply	other threads:[~2013-11-12 19:30 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 11:09 Increasing GNAT's heap Dmitry A. Kazakov
2013-11-12 13:26 ` Georg Bauhaus
2013-11-12 14:00   ` Dmitry A. Kazakov
2013-11-12 17:31     ` Paul Rubin
2013-11-13  8:00       ` Dmitry A. Kazakov
2013-11-12 19:30     ` Georg Bauhaus [this message]
2013-11-12 22:03 ` Florian Weimer
2013-11-13  8:05   ` Dmitry A. Kazakov
2013-11-13 15:41     ` Oliver Kleinke
2013-11-13  8:21 ` Ludovic Brenta
2013-11-13  8:23   ` Ludovic Brenta
2013-11-13  8:58   ` Dmitry A. Kazakov
2013-11-13 11:04     ` Georg Bauhaus
2013-11-13 13:31       ` Dmitry A. Kazakov
2013-11-13 15:39         ` Oliver Kleinke
2013-11-13 16:07           ` Eryndlia Mavourneen
2013-11-13 16:11             ` Eryndlia Mavourneen
2013-11-13 17:27           ` Dmitry A. Kazakov
2013-11-13 17:41             ` Eryndlia Mavourneen
2013-11-13 18:02               ` Dmitry A. Kazakov
2013-11-13 15:37       ` Oliver Kleinke
2013-11-13 15:32     ` Oliver Kleinke
2013-11-13 17:36       ` Dmitry A. Kazakov
2013-11-13 18:44         ` Oliver Kleinke
2013-11-13 22:08     ` Ludovic Brenta
2013-11-14  8:51       ` Dmitry A. Kazakov
2013-11-14 10:50         ` Georg Bauhaus
2013-11-14 11:16           ` Dmitry A. Kazakov
2013-11-14 13:07 ` Marius Amado-Alves
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox