comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry <lanceboyle@qwest.net>
Subject: Re: segfault with large-ish array with GNAT
Date: Thu, 18 Mar 2010 17:44:59 -0700 (PDT)
Date: 2010-03-18T17:44:59-07:00	[thread overview]
Message-ID: <e9cf1862-2ccc-45c7-9863-c8f2503f7a91@k5g2000pra.googlegroups.com> (raw)
In-Reply-To: c15097ed-1187-45ac-87e4-760f71eae9d3@33g2000yqj.googlegroups.com

On Mar 18, 3:23 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Jeffrey Creem wrote on comp.lang.ada:
<snip>
> > If you want the memory to come from the heap, you need to declare the
> > variables inside of packages instead of inside procedures. You can then
> > avoid using access types.
<snip>
> > package do_stuff is
> >     procedure no_bomb;
> > end do_stuff;
>
> > package body do_stuff is
> >       type Float_Array_Type is array (Integer range <>) of Long_Float;
> >       -- 1_048_343 causes segmentation fault, 1_048_342  does not.
> >       x : Float_Array_Type(1 .. 1_048_343);
>
> >      procedure No_bomb is
>
> >      begin
> >        x(1) := 1.0;
> >      end No_bomb;
> > end do_stuff;
>
> > with do_stuff;
> > procedure stuff is
>
> > begin
> >     do_stuff.No_Bomb;
> > end stuff;
>
> No, the array is not in the heap in this case; it is in the executable
> program's data segment. This may increase the size of the binary file.
>
> To ensure that the array is on the heap, it is necessary to use an
> access type and an allocator, e.g.:
>
> type Float_Array_Access_Type is access Float_Array_Type;
> x : Float_Array_Access_Type := new Float_Array_Type (1 .. 1_048_343);
>
> --
> Ludovic Brenta.

This (using a package) works. I made two Long_Float arrays of
100_000_000 length. The binary size is 292 KB (I included Text_IO)
regardless of the size of the arrays.

I'm not sure if I like the programming style better than using access
variables. I would have to essentially embed my entire program in a
package. And it seems to become impossible to selectively release
memory as is possible with access types. But it does solve my problem.

I programmed Pascal on Mac OS < 10 for years using pointers to arrays.
IIRC the stack was 32 KB.

Jerry



  reply	other threads:[~2010-03-19  0:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-17 19:21 segfault with large-ish array with GNAT Jerry
2010-03-17 19:36 ` Gautier write-only
2010-03-17 19:58   ` Georg Bauhaus
2010-03-18  6:45     ` Jerry
2010-03-18  7:52       ` Ludovic Brenta
2010-03-18 23:57         ` Robert A Duff
2010-03-18 10:13       ` Jeffrey Creem
2010-03-18 10:23         ` Ludovic Brenta
2010-03-19  0:44           ` Jerry [this message]
2010-03-18 19:51         ` Adam Beneschan
2010-03-18 14:44       ` John B. Matthews
2010-03-19  4:44         ` Jeffrey R. Carter
2010-03-19  8:14           ` John B. Matthews
2010-03-18 15:36       ` Gautier write-only
2010-03-18 16:46       ` tmoran
2010-03-18 19:11         ` Warren
2010-03-18 17:03       ` Warren
2010-03-18 20:38         ` Maciej Sobczak
2010-03-19 13:26           ` Charmed Snark
2010-03-19 17:27             ` tmoran
2010-03-19 18:02               ` Simon Wright
2010-03-19 20:10                 ` Warren
2010-03-19 21:50                 ` Adam Beneschan
2010-03-19 20:24               ` Warren
2010-03-19 20:38           ` Warren
2010-03-19  8:31         ` Ludovic Brenta
2010-03-19 13:20           ` Warren
2010-03-19 12:04       ` Brian Drummond
2010-03-19 19:22         ` Jerry
2010-03-19 20:22         ` Jeffrey R. Carter
2010-03-19 23:24           ` Jerry
2010-03-20  0:25             ` Jeffrey R. Carter
2010-05-07 21:58       ` Raising the stack limit (was: segfault with large-ish array with GNAT) Björn Persson
2010-03-17 19:57 ` segfault with large-ish array with GNAT jonathan
replies disabled

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