comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@ofir.dk>
Subject: Use of Unchecked_Deallocation and pragma Controlled
Date: 25 Nov 2004 00:47:59 +0100
Date: 2004-11-25T00:47:59+01:00	[thread overview]
Message-ID: <m3fz2yajww.fsf@0x535ba146.boanxx18.adsl-dhcp.tele.dk> (raw)

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?

Regards,
- Mark Lorenzen



             reply	other threads:[~2004-11-24 23:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-24 23:47 Mark Lorenzen [this message]
2004-11-25  1:10 ` Use of Unchecked_Deallocation and pragma Controlled David Botton
2004-11-25  6:25 ` Simon Wright
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