comp.lang.ada
 help / color / mirror / Atom feed
* Destroy and Unchecked Deallocation
@ 1988-12-06 13:08 TUFFS1
  1988-12-14 19:04 ` Destroy and Unchecked Deallocation (minor bug) William Thomas Wolfe,2847,
  0 siblings, 1 reply; 2+ messages in thread
From: TUFFS1 @ 1988-12-06 13:08 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1988-12-14 19:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-12-06 13:08 Destroy and Unchecked Deallocation TUFFS1
1988-12-14 19:04 ` Destroy and Unchecked Deallocation (minor bug) William Thomas Wolfe,2847,

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