comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Questions on Storage Pools
Date: Tue, 13 Aug 2013 12:36:08 -0700 (PDT)
Date: 2013-08-13T12:36:08-07:00	[thread overview]
Message-ID: <988e9ddb-e58a-4d52-9b43-71a080890dd4@googlegroups.com> (raw)
In-Reply-To: <c7573456-e37d-43f4-ab44-e1b37ade914d@googlegroups.com>

On Monday, August 12, 2013 7:14:23 PM UTC+2, Adam Beneschan wrote:
> I think you're confusing "finalization" with "storage reclamation".  They're not the same thing.

I guess you're right. The dust falling out of the worn RM is clearing now.
Thanx Adam.

> An access type can have a Storage_Size clause, or it can have a Storage_Pool clause.  It cannot have both (13.11(3)).

Yes, I know.

> If it has a Storage_Size clause, the intent is that some block of memory (whose size is Storage_Size plus possibly a little extra) is set aside, and all "new" operations that return the access type use memory in that block for the new object.

I understand and know this. But: Is there a GNAT GPL 2013 bug in this program:

  declare
    type Dyn is new Ada.Finalization.Controlled with record
      I: Integer;
    end record;
    overriding procedure Finalize (X: in out Dyn) is
    begin
      Put_Line ("Finalizing" & Integer'Image (X.I));
    end Finalize;
    type Dyn_Access is access Dyn
      with Storage_Size => 100;
    procedure Free is new Ada.Unchecked_Deallocation (Dyn, Dyn_Access);
    -- Dyn_Access is frozen here, so the collection is implicitly defined here.
    Ptr: array (1 .. 5) of Dyn_Access;
  begin
    Ptr (1) := new Dyn'(Ada.Finalization.Controlled with I => 1);
    Ptr (2) := new Dyn'(Ada.Finalization.Controlled with I => 2);
    Ptr (3) := new Dyn'(Ada.Finalization.Controlled with I => 3);
    Free (Ptr (2));  -- Finalize is called here
    Ptr (2) := new Dyn'(Ada.Finalization.Controlled with I => 4);
    -- RM 7.6.1(11.1/3)
    -- Each nonderived access type T has an associated collection, which is the set of objects
    -- created by allocators of T... Unchecked_Deallocation removes an object from its collection.
    -- Finalization of a collection consists of finalization of each object in the collection,
    -- in an arbitrary order. The collection of an access type is an object implicitly declared
    -- at the following place:
    -- RM 7.6.1(11.2/3)
    -- For a named access type, the first freezing point (see 13.14) of the type.
    -- RM 13.11(18)
    -- If Storage_Size is specified for an access type, then ... the storage for the pool is
    -- reclaimed when the master containing the declaration of the access type is left.
    Put_Line ("Must finalize collection now and reclaim pool storage.");
  end;  -- no Finalize called here!

There is no finalization of the still existing allocated objects. The collection is dying, so it should be finalized and with it all still existing allocated objects. It's irrelevant if there is the aspect Storage_Size or not.

If there is Storage_Size, the storage will be freed. If there is none, the storage remains allocated (with finalized objects inside). Correct?


  reply	other threads:[~2013-08-13 19:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-10 21:45 Questions on Storage Pools AdaMagica
2013-08-12 17:14 ` Adam Beneschan
2013-08-13 19:36   ` AdaMagica [this message]
2013-08-13 20:21     ` Adam Beneschan
2013-08-13 21:02       ` Randy Brukardt
2013-08-14  7:40         ` AdaMagica
replies disabled

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