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-7-bit Path: g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!news.musoftware.de!wum.musoftware.de!news.mixmin.net!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Jeffrey Creem Newsgroups: comp.lang.ada Subject: Re: segfault with large-ish array with GNAT Date: Thu, 18 Mar 2010 06:13:18 -0400 Organization: A noiseless patient Spider Message-ID: References: <642ddf8b-1d45-4f74-83ad-2c755040ca33@k24g2000pro.googlegroups.com> <4ba13454$0$6720$9b4e6d93@newsspool2.arcor-online.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 18 Mar 2010 10:15:06 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="CFAiAG8rVxPpF2avg9j34A"; logging-data="31950"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tK8PDAN91vq5de5zgk0+jQDCnoae2K/M=" User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) In-Reply-To: Cancel-Lock: sha1:aiaaswOKGRq37WlIKMUitAEwp0I= Xref: g2news2.google.com comp.lang.ada:10616 X-Original-Bytes: 3137 Date: 2010-03-18T06:13:18-04:00 List-Id: Jerry wrote: > Thanks for the helpful comments. > > So here's me being naive: I would have thought that Ada (or GNAT > specifically) would be smart enough to allocate memory for large > objects such as my long array in a transparent way so that I don't > have to worry about it, thus (in the Ada spirit) making it harder to > screw up. (Like not having to worry about whether arguments to > subprograms are passed by value or by reference--it just happens.) > > But it seems that I will have to allocate memory for large objects > using pointers (and thus take the memory from the heap). Is that > right? > > In this context, is there any advantage to declaring the large object > inside a declare block? Would that force the memory to be allocated > from the heap? > > Jerry 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. declare blocks will not help. As for wishing that the compiler would automatically switch between heap and stack, that would probably be a terrible idea and render the language quite unsuitable for embedded systems. -- warning, not even compiled early morning code example below 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;