* Re: Question: inheritance from non-tagged types.
[not found] <35D16EB9.195B3686@tech.swh.lv>
@ 1998-08-12 0:00 ` Samuel Tardieu
1998-08-12 0:00 ` Tom Moran
1 sibling, 0 replies; 2+ messages in thread
From: Samuel Tardieu @ 1998-08-12 0:00 UTC (permalink / raw)
>>>>> "Maxim" == Maxim Senin <maks@tech.swh.lv> writes:
Maxim> - is it correct to derive tagged type from non-tagged type like
Maxim> here I derive Object from Controlled?
It is not correct to derive a tagged type from a non-tagged
type. However, Ada.Finalization.Controlled *is* a tagged type, so your
question does not apply here, and your derivation is correct.
Maxim> - I derive Object from Controlled to allow garbage collection
Maxim> for all Objects and their derivatives. Is it correct? Will it
Maxim> work? I know garbage collection is not implemented in most
Maxim> ADA compilers, but it's defined by language standard. I
Maxim> believe that if I write program for "standard ADA compiler"
Maxim> this code is correct. Is it true?
Having a type deriving from Controlled does not trigger any magic
garbage collection, it only lets you define Initialize, Adjust and
Finalize primitives that will be called respectively at initialization
time, copy time and finalization time.
If an Ada[1] compiler uses a garbage collector, you don't need to use a
controlled object to trigger it, those are orthogonal issues.
However, if you want to write portable code, it is safer to use
instanciations of Ada.Unchecked_Deallocation to ensure that you will
reclaim unused storage[2].
Sam
Footnotes:
[1] Yes, Ada, not ADA
[2] Even if you have no guarantee that storage will get reclaimed in
fact :)
--
Samuel Tardieu -- sam@ada.eu.org
^ permalink raw reply [flat|nested] 2+ messages in thread