From: Ted Dennison <dennison@telepath.com>
Subject: Re: how do i include 111111 in an enumaration type ?
Date: 1999/10/13
Date: 1999-10-13T00:00:00+00:00 [thread overview]
Message-ID: <7u28tv$rph$1@nnrp1.deja.com> (raw)
In-Reply-To: 380485d2_1@news1.prserv.net
In article <380485d2_1@news1.prserv.net>,
"Matthew Heaney" <matthew_heaney@acm.org> wrote:
> In article <slrn808j1s.o7.lutz@taranis.iks-jena.de> , lutz@iks-jena.de
> (Lutz Donnerhacke) wrote:
>
> > From reading the Rationale and Reference Manual, the novice (like
> > me) can not deduce, that this 'Unchecked_'-Package is required for
> > normal usage.
>
> Unchecked_Deallocation is not required for normal usage.
Well, that depends on what you define as "normal".
> There are idioms for implementing abstractions that use the heap or
> some form of indirection. Basically, you want to hide all of that
> from the client.
True. But you are talking perspective. That doesn't let Lutz off the
hook if he happens to be *writing* the code that "clients" are using.
My general idom for this is:
o Don't worry about it if the allocations only happen once and you
are only running on "heavy" OS's that clean up allocated memory when the
program exits (EG: Unix, Win32).
o If you allocate memory for temporary processing in a routine, make
sure to (unchecked_)deallocte it before you return.
o As a special case of the above, if you need to do a lot of
allocations in a routine that get cleaned up at the end, and know the
maximum total memory size you will ever need, consider creating an
access type in the routine and specifying a storage pool size for it.
All objects allocated into values of that access type will then get
automagicly deallocted when the routine ends.
o If you allocate memory for non-transient use in a routine, keep
track of it in some kind of "cookie" object (typically as part of
another private object that is already passed in), and provide a
"cleanup" routine to the user. Both routines should be copiously
commented as to when "cleanup" needs to be called.
o As a speicial case of the above, if the allocation happens as part
of an initialization, consider using a controlled type (derived from
Ada.Finialization.Controlled and .Limited_Controled), as the calls to
initialize and cleanup will be made automaticly.
o Avoid returning a pointer to allocted memory to the client, for
them to clean up manually themselves. (This was the whole of Matt's
point, I believe). That's a truly ugly interface. In fact it gives
"interface" a bad name.
--
T.E.D.
Sent via Deja.com http://www.deja.com/
Before you buy.
next prev parent reply other threads:[~1999-10-13 0:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <7tsq3o$92p$1@minus.oleane.net>
[not found] ` <38021792_4@news1.prserv.net>
[not found] ` <slrn80495c.2a2.aidan@skinner.demon.co.uk>
1999-10-11 0:00 ` how do i include 111111 in an enumaration type ? Keith Thompson
1999-10-12 0:00 ` Sybs ALHABSHI
1999-10-12 0:00 ` Lutz Donnerhacke
1999-10-12 0:00 ` Matthew Heaney
1999-10-12 0:00 ` Lutz Donnerhacke
1999-10-12 0:00 ` Ted Dennison
1999-10-12 0:00 ` Ted Dennison
1999-10-13 0:00 ` Lutz Donnerhacke
1999-10-13 0:00 ` Matthew Heaney
1999-10-13 0:00 ` Ted Dennison [this message]
1999-10-12 0:00 ` Matthew Heaney
1999-10-12 0:00 ` Ehud Lamm
1999-10-12 0:00 ` Nick Roberts
1999-10-14 0:00 ` Sybs ALHABSHI
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox