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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: How to get Ada to 'cross the chasm'? Date: Mon, 7 May 2018 18:44:16 -0500 Organization: JSA Research & Innovation Message-ID: References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com><878t9nemrl.fsf@nightsong.com> <87h8nl50rw.fsf@nightsong.com> <87d0y97lda.fsf@nightsong.com> Injection-Date: Mon, 7 May 2018 23:44:18 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="4168"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:52077 Date: 2018-05-07T18:44:16-05:00 List-Id: "Paul Rubin" wrote in message news:87d0y97lda.fsf@nightsong.com... > Niklas Holsti writes: >> One reason is that when a function evaluates an expression that >> creates an object of a large, dynamic size (eg. an array expression) >> on the secondary stack, this object can be returned /in situ/ as the >> function's return value, without being copied. > > Ok, but that pattern is so common that allocating the space in the > primary stack before calling the function is a standard optimization > that every serious C++ compiler knows how to do. Then the function > writes the result into the primary stack and the caller can still use it > after the function returns. Could Ada not do it the same way? It usually does when the size of the object is known at compile time. The secondary stack is mainly used for returning object whose size is not known at compile-time. (Note: I don't know the details of the GNAT implementation.) The classic example is a function returning a string: function My_Image (Val : in Integer) return String; Here, the size of the string returned isn't known until the function figures it out; there's no way for the caller to know that (as it doesn't necessarily know anything about the body). Janus/Ada returns such objects on the heap rather than horsing around with a second stack. (When I get a Round Tuit, I'm going to move static-sized objects to essentially be parameters to the function, one of zillion projects that I need to do someday soon.) It keeps track of them and frees them up when they're no longer needed (using a mechanism very similar to finalization). The cost isn't much different than the secondary stack, and you can't really analyze either very well. Randy. Randy.