comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent Guerby <guerby@acm.org>
Subject: Re: Deallocating an object referenced via a classwide access type.
Date: 2000/01/11
Date: 2000-01-11T19:28:44+00:00	[thread overview]
Message-ID: <86k8lgmmig.fsf@ppp-112-82.villette.club-internet.fr> (raw)
In-Reply-To: slrn87l2rt.15e.aidan@skinner.demon.co.uk

Aidan wrote:
> I can't use Ada.Unchecked_Deallocation, since My_Thing might be a Foo
> or it might be a New_Foo.

May be I'm missing something obvious about your question and/or the
Ada RM but the code attached at the end of this message works for
AFAIK (I edited your spec so that it compiles ;-). The only thing
special (due to the class wide nature of the Object formal) is that
the Finalize call made as part of the Free call before returning the
memory to the system will be dispatching (you didn't provide Finalize
on Foo but I guess you have one ;-).

--LG

with Ada.Unchecked_Deallocation;
package body Foo_Package is

   procedure Deallocate (Object : in out Foo) is
      procedure Free is new Ada.Unchecked_Deallocation (Foo'Class, Foo_Access);
   begin
      Free (Object.My_Thing);
   end Deallocate;

end Foo_Package;

with Ada.Finalization;
package Foo_Package is

  type Foo is new Ada.Finalization.Controlled with private;

  type Foo_Access is access all Foo'Class;

  type New_Foo is new Foo with private;

private

  type Foo is new Ada.Finalization.Controlled with record
     My_Thing : Foo_Access := null;
  end record;

  procedure Deallocate (Object : in out Foo);

  type New_Foo is new Foo with null record;

end Foo_Package;






      parent reply	other threads:[~2000-01-11  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-11  0:00 Deallocating an object referenced via a classwide access type Aidan Skinner
2000-01-10  0:00 ` Matthew Heaney
2000-01-11  0:00   ` Matthew Heaney
2000-01-11  0:00 ` Tucker Taft
2000-01-11  0:00 ` Laurent Guerby [this message]
replies disabled

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