From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ae395e5c11de7bc9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!k5g2000pra.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: Re: segfault with large-ish array with GNAT Date: Thu, 18 Mar 2010 17:44:59 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <642ddf8b-1d45-4f74-83ad-2c755040ca33@k24g2000pro.googlegroups.com> <4ba13454$0$6720$9b4e6d93@newsspool2.arcor-online.net> NNTP-Posting-Host: 75.172.190.146 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1268959499 17876 127.0.0.1 (19 Mar 2010 00:44:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 19 Mar 2010 00:44:59 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k5g2000pra.googlegroups.com; posting-host=75.172.190.146; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/528.16+(KHTML, like Gecko, Safari/528.16) OmniWeb/v622.8.0,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:10630 Date: 2010-03-18T17:44:59-07:00 List-Id: On Mar 18, 3:23=A0am, Ludovic Brenta wrote: > Jeffrey Creem wrote on comp.lang.ada: > > 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. > > package do_stuff is > > =A0 =A0 procedure no_bomb; > > end do_stuff; > > > package body do_stuff is > > =A0 =A0 =A0 type Float_Array_Type is array (Integer range <>) of Long_F= loat; > > =A0 =A0 =A0 -- 1_048_343 causes segmentation fault, 1_048_342 =A0does n= ot. > > =A0 =A0 =A0 x : Float_Array_Type(1 .. 1_048_343); > > > =A0 =A0 =A0procedure No_bomb is > > > =A0 =A0 =A0begin > > =A0 =A0 =A0 =A0x(1) :=3D 1.0; > > =A0 =A0 =A0end No_bomb; > > end do_stuff; > > > with do_stuff; > > procedure stuff is > > > begin > > =A0 =A0 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 :=3D 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