Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Prohibiting...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 14 of 20 Topic 5612 of 5931
Post > Topic >>

Re: Prohibiting dynamic allocation for the given type

by Robert A Duff <bobduff@[EMAIL PROTECTED] > Mar 19, 2008 at 08:48 PM

Eric Hughes <eric.eh9@[EMAIL PROTECTED]
> writes:

> If you want to control lifetime, you can control either the allocation
> lifetime or the functional lifetime; the second is a subset of the
> first.  As you've pointed out, you don't get a lot of control over
> allocation lifetime.  But functional lifetime you can control.  Here's
> how I would approach it.
>
> First, make the utility of your type depend for its function on the
> existence of some other object.  This likely goes into a constructor
> function, but need not.  Your type would contain some kind of a weak
> accessor, one that doesn't enforce the existence of its referent.
> Gate all utility upon the existence of this referent.  If the referent
> is absent, do nothing or throw an exception, whatever.  This check is
> cheap; it's that some access value is not null.  Use finalization in
> the referent to update the accessor value in your type.  This gives
> you a dependency between objects, regardless of how the referent
> object is allocated.
>
> Second, when instantiating the object, make it refer to a sentry
> object with block scope.  When the sentry object goes out of scope,
> your original object will stop working.  I frequently use nested
> declare/begin/end blocks within subprogram definitions to trigger
> sentry finalization.
>
> You'll still have to do***ent that if you want scope lifetime for your
> object's utility, you'll have to make it dependent upon a scoped
> variable.  But at that point the code explicitly captures an intention
> for scope lifetime.

I don't understand this method.  Maybe you could give an outline of the
code.  In particular, how do you ensure that the "sentry" is not
heap-allocated?  If you trust the client on that, then why not trust
the client to avoid heap allocation for the "real" object in the
first place?  I must be missing something...

- Bob
 




 20 Posts in Topic:
Prohibiting dynamic allocation for the given type
Maciej Sobczak <see.my  2008-03-18 14:30:37 
Re: Prohibiting dynamic allocation for the given type
gpriv@[EMAIL PROTECTED]   2008-03-18 20:06:45 
Re: Prohibiting dynamic allocation for the given type
Maciej Sobczak <see.my  2008-03-19 01:24:57 
Re: Prohibiting dynamic allocation for the given type
Georg Bauhaus <rm.tsoh  2008-03-19 12:31:23 
Re: Prohibiting dynamic allocation for the given type
Georg Bauhaus <rm.tsoh  2008-03-19 23:17:46 
Re: Prohibiting dynamic allocation for the given type
gpriv@[EMAIL PROTECTED]   2008-03-19 06:13:16 
Re: Prohibiting dynamic allocation for the given type
Maciej Sobczak <see.my  2008-03-19 06:54:45 
Re: Prohibiting dynamic allocation for the given type
Pascal Obry <pascal@[E  2008-03-19 15:12:05 
Re: Prohibiting dynamic allocation for the given type
"Randy Brukardt"  2008-03-19 18:08:34 
Re: Prohibiting dynamic allocation for the given type
Simon Wright <simon.j.  2008-03-20 20:26:19 
Re: Prohibiting dynamic allocation for the given type
Adam Beneschan <adam@[  2008-03-19 07:38:37 
Re: Prohibiting dynamic allocation for the given type
gpriv@[EMAIL PROTECTED]   2008-03-19 08:43:17 
Re: Prohibiting dynamic allocation for the given type
Eric Hughes <eric.eh9@  2008-03-19 09:37:46 
Re: Prohibiting dynamic allocation for the given type
Robert A Duff <bobduff  2008-03-19 20:48:18 
Re: Prohibiting dynamic allocation for the given type
gpriv@[EMAIL PROTECTED]   2008-03-19 16:40:46 
Re: Prohibiting dynamic allocation for the given type
Robert A Duff <bobduff  2008-03-19 20:43:56 
Re: Prohibiting dynamic allocation for the given type
Maciej Sobczak <see.my  2008-03-20 14:11:29 
Re: Prohibiting dynamic allocation for the given type
Eric Hughes <eric.eh9@  2008-03-20 14:35:42 
Re: Prohibiting dynamic allocation for the given type
Eric Hughes <eric.eh9@  2008-03-20 15:03:46 
Re: Prohibiting dynamic allocation for the given type
"Randy Brukardt"  2008-03-20 20:04:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:21:35 CDT 2008.