comp.lang.ada
 help / color / mirror / Atom feed
From: TUFFS1@alcoa.com
Subject: Destroy and Unchecked Deallocation
Date: 6 Dec 88 13:08:00 GMT	[thread overview]
Message-ID: <8812140455.AA16285@ajpo.sei.cmu.edu> (raw)

Bill Wolfe writes (Info-Ada Digest V88 #244, 23 Nov 1988):
>...
>> 
>> This needs clarification; what does a DESTROY procedure do that
>> UNCHECKED_DEALLOCATION doesn't?
>
>      Consider an ADT which contains pointers to substructures.
>      A user declares an access type pointing to an instance of your
>      ADT, and uses UNCHECKED_DEALLOCATION to destroy that instance
>      after finishing with it.  UNCHECKED_DEALLOCATION will not 
>      recursively chase down and free up what might constitute 
>      over 99% of the space occupied by the ADT.   Similarly, if your
>      ADT uses another ADT in its implememtation, your DESTROY procedure
>      will include a call to the DESTROY procedure of the sub-ADT,
>      but UNCHECKED_DEALLOCATION will remain oblivious to the method
>      which must be used to properly destroy the sub-ADT.
>...

I believe the effect you want can be implemented within Ada as it stands.  
Following LRM 13.10 (2), define a new Deallocate generic, and have the 
user avoid direct reference to Unchecked_Deallocation:

generic
  type Object is limited private;
  type Name is access Object;
  with procedure Destroy(Y: in out Object) is <>;
procedure Deallocate(X: in out Name);

with Unchecked_Deallocation;
procedure Deallocate(X: in out Name) is
  procedure Clean_Up is new Unchecked_Deallocation(Object, Name);
begin
  Destroy(X.all);
  Clean_Up(X);
end Deallocate;


Simon Tuffs
Tuffs@Alcoa.com

             reply	other threads:[~1988-12-06 13:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1988-12-06 13:08 TUFFS1 [this message]
1988-12-14 19:04 ` Destroy and Unchecked Deallocation (minor bug) William Thomas Wolfe,2847,
replies disabled

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