comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: GNAT - return by anonymous access
Date: Tue, 27 Dec 2011 17:51:33 -0600
Date: 2011-12-27T17:51:33-06:00	[thread overview]
Message-ID: <jddlm7$euj$1@munin.nbi.dk> (raw)
In-Reply-To: bc9926b7-e35b-43a1-adf7-82a936141dd6@m7g2000vbc.googlegroups.com

"Simon Belmont" <sbelmont700@gmail.com> wrote in message 
news:bc9926b7-e35b-43a1-adf7-82a936141dd6@m7g2000vbc.googlegroups.com...
On Dec 22, 7:56 pm, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
...
>However, it's good
>to know that using a 'coextension' has such counter-intuitive
>operation.  I assumed that it would be functionally equivilent to
>simply declaring the object previously and initializing it with the
>exiting object, and certainly not different to the extent of, if I
>understand you correctly, not even using the heap at all.

A 'coextension' is supposed to have the same lifetime as the enclosing 
object. That means that if the enclosing object is declared on the stack, 
then the coextension should be allocated (at least logically) on the stack. 
Adding to this brew is the fact that limited objects are built-in-place, so 
the return statement you wrote is really creating the new object somewhere 
else (quite possibly on the stack). This requires a lot of shuffling, so it 
is not surprising that it can get buggy.

Janus/Ada allocates some dynamically sized objects on the heap (even when 
they logically are on the stack) and cleans them up when the stack is 
popped. So it isn't quite as hard for us (but it still is a struggle to get 
such things on the right list, and not one that is too inner). But for 
implementations that use a secondary stack for all such objects, this must 
be a nightmare (either leaking memory or freeing it too soon seems to be 
required).

                                   Randy.





  reply	other threads:[~2011-12-27 23:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17 19:17 GNAT - return by anonymous access Simon Belmont
2011-12-17 19:51 ` Simon Wright
2011-12-18  9:08 ` Georg Bauhaus
2011-12-19 23:46 ` Randy Brukardt
2011-12-20  0:14   ` Shark8
2011-12-20 23:18     ` Randy Brukardt
2011-12-21  0:44       ` Simon Belmont
2011-12-21  7:29         ` AdaMagica
2011-12-21 11:05           ` Georg Bauhaus
2011-12-21 11:43             ` AdaMagica
2011-12-21 12:05               ` Georg Bauhaus
2011-12-22  0:33                 ` Randy Brukardt
2011-12-22  0:33           ` Simon Belmont
2011-12-22  7:11             ` Adam Beneschan
2011-12-22 22:11               ` Simon Belmont
2011-12-23  0:56                 ` Randy Brukardt
2011-12-23 13:20                   ` Simon Belmont
2011-12-27 23:51                     ` Randy Brukardt [this message]
2011-12-20 23:53 ` anon
replies disabled

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