comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Use of Unchecked_Deallocation and pragma Controlled
Date: 25 Nov 2004 06:25:32 +0000
Date: 2004-11-25T06:25:32+00:00	[thread overview]
Message-ID: <x7v3byyzbqb.fsf@smaug.pushface.org> (raw)
In-Reply-To: m3fz2yajww.fsf@0x535ba146.boanxx18.adsl-dhcp.tele.dk

Mark Lorenzen <mark.lorenzen@ofir.dk> writes:

> When Unchecked_Deallocation is used to reclaim the storage claimed
> by an object, the pragma Controlled must be use to prevent automatic
> reclamation (ie. "garbage collection") of storage which would
> otherwise result in "double deallocation" of the object.
> 
> Example:
> 
> type Access_T is access T;
> Pragma Controlled (Access_T);
> 
> procedure Free is new Ada.Unchecked_Deallocation(T, Access_T);
> 
> begin
>   A : Access_T := new T;
>   B : Access_T := A;
> 
>   ...
> 
>   Free(T);    -- OK, reclaim the storage.
> end;          -- OK only if pragma Controlled has been applied.
>               -- Otherwise B could be reclaimed by garbage collection,
>               -- resulting in double deallocation of A.
> 
> Question: Do you guys actually use pragma Controlled even if no
> current Ada compiler generates code with garbage collection?

I don't believe there are any Ada compilers (other than those targeted
to a JVM) that do garbage collection.

But even if there were, it seems to me it would be a pretty crappy
implementation that didn't notice you doing the Free and remember
somehow not to collect the garbage. I rather suspect it wouldn't pass
ACATS either. I wouldn't buy it.

On the other hand, the AARM
<http://www.adaic.org/standards/95aarm/html/AA-13-11-3.html> goes into
a lot of detail about it, so perhaps I'm just confused .. thank
heavens the compiler I'm using doesn't do it! One less thing to worry
about.

-- 
Simon Wright                               100% Ada, no bugs.



  parent reply	other threads:[~2004-11-25  6:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-24 23:47 Use of Unchecked_Deallocation and pragma Controlled Mark Lorenzen
2004-11-25  1:10 ` David Botton
2004-11-25  6:25 ` Simon Wright [this message]
2004-11-26 13:11   ` Nick Roberts
replies disabled

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