Re: How to properly clean up an extended, generic structure?



Peter C. Chapin wrote:

Right now I'm working on a generic package that implements splay trees. My generic parameters look like:

generic
type Item_Type is private;
with function "<"(L : Item_Type; R : Item_Type) return Boolean;
package Splay_Tree is ...

Let me summarize the answers you've received, since some of them only address part of your concern.

Your tree should clean up after itself. You don't say if Splay_Tree provides ADTs or an ASM, but in either case controlled types are the way to achieve this (ARM 7.6). Then you don't need to have a visible Destroy operation, and the clients of your package aren't responsible for destroying a tree when it's no longer needed.

It's up to the clients of your package to arrange for finalization for the actual associated with Item_Type, if it's needed. Basically, if the actual needs finalization, then it should be a controlled type. If it's a controlled type, then its Finalization procedure will be called when an object ceases to exist, including due to deallocation.

--
Jeff Carter
"My mind is a raging torrent, flooded with rivulets of
thought, cascading into a waterfall of creative alternatives."
Blazing Saddles
89
.



Relevant Pages

  • Re: Libraries written in Ada
    ... but any compiler that conforms to the spec) needs runtime ... So it's not possible to reset a package in the midst of program execution? ... > system called controled objects. ... What if a package doesn't have any specific finalization code? ...
    (comp.lang.ada)
  • Re: Distributed Ada, robustness etc.
    ... Finalize procedure is called when the partition terminates. ... Note that finalization occurs in reverse order of elaboration. ... this means that your package is elaborated *before* the PCS. ...
    (comp.lang.ada)
  • Re: Distributed Ada, robustness etc.
    ... Note that finalization occurs in reverse order of elaboration. ... this means that your package is elaborated *before* the PCS. ...
    (comp.lang.ada)
  • Re: How to properly clean up an extended, generic structure?
    ... My generic parameters look like: ... type Item_Type is private; ... If you want your package to be usable with non-controlled type, you can also do: ...
    (comp.lang.ada)