comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Chunks of finalized
Date: 1997/10/03
Date: 1997-10-03T00:00:00+00:00	[thread overview]
Message-ID: <3434F45A.37ED@gsfc.nasa.gov> (raw)
In-Reply-To: 6129sn$n91$1@goanna.cs.rmit.edu.au


Richard A. O'Keefe wrote:
> =

>     type Stack_Chunk is array (0 .. Chunk_Size - 1) of Stack_Element;
> =

>     type Stack_Node;
>     type Stack_Link is access Stack_Node;
>     type Stack_Node is
>        record
>           Data: Stack_Chunk;
>           Next: Stack_Link;
>        end record;
> =

>     type Stack is
>        record
>           Count: Natural;
>           List : Stack_Link;
>           Spare: Stack_Link;
>        end record;
> =

> The problem is, what if the stack elements are derived from
> Ada.Finalization.Controlled?

I don't see why this is an issue at all.

> The lifetime of an object contains at least the following steps:
> =

>     1. allocate raw storage
>     2. initialise
>     3. use
>     4. finalise
>     5. release raw storage.
> =

> In this stack example, if Chunk_Size is 10 and Count is 25, we might
> have 3 records in the List and 1 Spare, for a total of 40 > Stack_Eleme=
nts
> that have been _allocated_, but only 25 of which are _in use_.

Do you want to call Finalize on the elements that have been Popped? =

 =

> I've been trying to figure out how to do this in Ada, and I don't > thi=
nk
> I can.  If one is trying to implement a generic container data > struct=
ure,
> there is nothing one can do to tell the elements 'stay alive but > forg=
et
> everything', except include such an operation as one of the generic
> parameters.

I'm not clear what you mean by "forget everything", but it seems like
you want to call Finalize on the stack elements. The issue is how to get
the stack container to do this. One way would be to deallocate, which
you are trying to avoid. Another way is to assign another object to the
stack slot, which will be done by the next Push. The only other way is
to explicitly call Finalize. If your container is a generic that takes a
type Stack_Element_Type, then make it also take an operation
Finalize_Stack_Element, which is called by Pop (_after_ copying :), and
can be null for non-controlled elements. This seems to be what you are
suggesting.

Another question is why you need to call Finalize when the item is
popped, rather than waiting until the item is overwritten or
deallocated. The item will never be used in any way, so even if it
contains dangling pointers, you are safe. =

 =

> What have I missed?

Nothing, as far as I can see.
 =

> How is it that people using the Booch components don't find this
> a problem?  (I haven't understood anything in the current Booch-95
> components as doing this.)

I haven't read the Booch components in enough detail to address this. =


> =

> --
> John =C6neas Byron O'Keefe; 1921/02/04-1997/09/27; TLG,TLTA,BBTNOTL.
> Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.

-- =

- Stephe




  reply	other threads:[~1997-10-03  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-03  0:00 Chunks of finalized Richard A. O'Keefe
1997-10-03  0:00 ` Stephen Leake [this message]
1997-10-04  0:00   ` Robert A Duff
1997-10-06  0:00     ` Tucker Taft
1997-10-07  0:00       ` Richard A. O'Keefe
1997-10-03  0:00 ` Robert A Duff
1997-10-05  0:00 ` Matthew Heaney
replies disabled

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