comp.lang.ada
 help / color / mirror / Atom feed
* Use of Unchecked_Deallocation and pragma Controlled
@ 2004-11-24 23:47 Mark Lorenzen
  2004-11-25  1:10 ` David Botton
  2004-11-25  6:25 ` Simon Wright
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Lorenzen @ 2004-11-24 23:47 UTC (permalink / 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



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

end of thread, other threads:[~2004-11-26 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2004-11-26 13:11   ` Nick Roberts

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