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: a07f3367d7,aa14979d20ba3045 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!b1g2000vbc.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Allocation question Date: Mon, 11 May 2009 06:27:06 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4a07fc7a$0$2855$ba620e4c@news.skynet.be> <54897f26-0d3f-421e-9426-1822a531674e@p4g2000vba.googlegroups.com> <87ljp3hlkn.fsf@nbi.dk> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1242048426 18528 127.0.0.1 (11 May 2009 13:27:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 11 May 2009 13:27:06 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b1g2000vbc.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5765 Date: 2009-05-11T06:27:06-07:00 List-Id: Jacob Sparre Andersen wrote on comp.lang.ada: > Is there something which prevents an Ada compiler from allocating > large, local objects on the heap rather than on the stack? > > Would it be very complicated to introduce a rule in a compiler (not in > the language), which makes local objects larger than some limit be > allocated on the stack? An interesting thought. I just re-read 3.11 and it only says that declarative_parts are "elaborated". 3.3.1(18/2) is similarly terse on object_declarations, saying only that "the object is created". The RM doesn't seem to have a concept of a stack at all; this is left to the implementation. So, I suppose you are correct that a compiler can choose to allocate everything on the heap. In fact, I suspect that that's what compilers targetting the Java virtual machine have to do. For other targets, I guess it would make sense for some compilers to introduce a pragma allowing the programmer to specify where the object should be. For heap-allocated objects, I don't think it would be overly difficult to replace an object_declaration with a synthetic controlled object that encapsulates it in the manner I described earlier. -- Ludovic Brenta.