comp.lang.ada
 help / color / mirror / Atom feed
From: Per Sandberg <per.s.sandberg@bahnhof.se>
Subject: Re: How do typical Ada calling conventions work ?
Date: Tue, 25 Aug 2015 07:32:12 +0200
Date: 2015-08-25T07:32:12+02:00	[thread overview]
Message-ID: <55dbfddd$0$20676$862e30e2@ngroups.net> (raw)
In-Reply-To: <mrg4cb$qnh$1@loke.gir.dk>



Den 2015-08-25 00:03, Randy Brukardt skrev:
> "Hadrien Grasland" <hadrien.grasland@gmail.com> wrote in message
> news:2541f7b7-b728-421b-96cf-e0d656e984a2@googlegroups.com...
> ...
>> Thanks for your answers ! These are some pretty nice ways to do it instead
>> indeed.
>>
>> I'm glad the secondary stack approach won in the end for GNAT, it sounds
>> more
>> efficient, clean and scalable than what they were attempting in the
>> beginning.
>
> I doubt that. The scheme Janus/Ada uses is much simpler: the memory is
> allocated off of a special storage pool and it is then freed using the same
> mechanism that does other finalization (indeed, the memory management [which
> we used in Ada 83] was repurposed to do finalization, rather than the other
> way around).
>
> This is probably not as efficient as the secondary stack approach, but I
> find that irrelevant in 99.9% of programs. All functions that return
> non-elementary types are somewhat more expensive than the similar parameter
> passing, so if efficiency is a primary concern, one must use procedures
> rather than functions. The cases where function return by secondary stack
> would be efficient enough but function return by heap is not efficient
> enough are going to be quite rare [in the vast majority of cases either both
> are good enough or neither are] -- thus there are better things to spend
> effort on.
>
>                                                      Randy.
>
>
If you want to use a function "returning" large or limited objects you 
could always use the "extended return" where the returned object will be 
created in place.

type large_or_limited is ....;
function my_function return large_or_limited is
begin
    return ret : large_or_limited do
       do_what_you_need;
    end return;
end my_function;

/Per


  reply	other threads:[~2015-08-25  5:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-21  8:37 How do typical Ada calling conventions work ? Hadrien Grasland
2015-08-21 10:41 ` Markus Schöpflin
2015-08-21 12:47   ` Niklas Holsti
2015-08-22  8:31     ` Hadrien Grasland
2015-08-24 22:03       ` Randy Brukardt
2015-08-25  5:32         ` Per Sandberg [this message]
2015-08-25  7:05           ` AdaMagica
2015-08-25  7:28             ` AdaMagica
2015-08-31 23:01           ` Randy Brukardt
2015-08-25 18:38 ` gautier_niouzes
2015-08-26 15:53   ` Hadrien Grasland
replies disabled

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