comp.lang.ada
 help / color / mirror / Atom feed
* Unchecked_Deallocation of class-wide objects
@ 2009-09-28  8:43 Maciej Sobczak
  2009-09-28  9:12 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 2+ messages in thread
From: Maciej Sobczak @ 2009-09-28  8:43 UTC (permalink / raw)


Is it legal and safe to deallocate class-wide objects?

The problem is that such an object is allocated with its concrete
type, whereas deallocation is defined for its class-wide type.
Consider:

type Shape is tagged private;
type Shape_Access is access Shape'Class;

procedure Free_Shape is new Ada.Unchecked_Deallocation
   (Object => Shape'Class, Name => Shape_Access);
-- ...

type Circle is new Shape with ...
-- ...
C : Shape_Access := new Circle;
-- ...
Free_Shape (C);

Is the Circle object allocated on the Shape-wide storage pool? From
what I understand, this is the condition for the above to work
properly.
What if Circle is allocated for some Circle_Access type which is then
converted to Shape_Access? Can it be safely deallocated?

I believe that the above is a pretty standard use-case, but I would
like to confirm that. Unfortunately, AARM is not very explicit about
this subject.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



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

end of thread, other threads:[~2009-09-28  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-28  8:43 Unchecked_Deallocation of class-wide objects Maciej Sobczak
2009-09-28  9:12 ` Dmitry A. Kazakov

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