From: Samuel Tardieu <sam@ada.eu.org>
Subject: Re: Question: inheritance from non-tagged types.
Date: 1998/08/12
Date: 1998-08-12T00:00:00+00:00 [thread overview]
Message-ID: <m367fyqv2d.fsf@zaphod.enst.fr> (raw)
In-Reply-To: 35D16EB9.195B3686@tech.swh.lv
>>>>> "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
prev parent reply other threads:[~1998-08-12 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <35D16EB9.195B3686@tech.swh.lv>
1998-08-12 0:00 ` Question: inheritance from non-tagged types Tom Moran
1998-08-12 0:00 ` Samuel Tardieu [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox