comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Array of unbounded strings, memory leakage?
Date: Tue, 22 Oct 2002 10:36:28 -0400
Date: 2002-10-22T10:36:28-04:00	[thread overview]
Message-ID: <uraojdme8n8ub2@corp.supernews.com> (raw)
In-Reply-To: pan.2002.10.20.16.23.48.564315@jps-nospam.net


"Eric G. Miller" <egm2@jps-nospam.net> wrote in message
news:pan.2002.10.20.16.23.48.564315@jps-nospam.net...
> I know the following isn't terribly efficient, but does the Resize
> procedure leak memory?

Instances of Unbounded_String --even if they are components of an array--
don't leak memory.  Typically they would be implemented as a private
derivation from Controlled.

Of course, if you allocate the array on the heap, and then forget to
deallocate the array, then of course that is a memory leak.

Programmers sometimes forget (or perhaps don't even realize) that
Unchecked_Deallocation is "aware" that the object being deallocating is
Controlled, and Finalization will occur before the actual memory
reclaimation happens.  This is not unlike how delete works in C++: the dtor
will get invoked prior to actual deallocation.

The Charles library already has an unbounded vector you could use, instead
of manipulating unbounded arrays directly.  For example:

package Unbounded_String_Vectors is
   new Charles.Vectors.Unbounded (Unbounded_String);
use Unbounded_String_Vectors;

V : Container_Type;
...
Resize (V, Size => N);
--or--
Assign (V, Length => N);
--or--
Assign (V, Length => N, Item => Null_Unbounded_String);

The Charles vector differentiates between "length" and "size".  It wasn't
clear from your example whether the length or size needed modification, so
the fragment above shows you how to do both.

http://home.earthlink.net/~matthewjheaney/charles/charles-vectors-unbounded.
html

I just released a new version (20021021) of the library, with better error
checking.

http://home.earthlink.net/~matthewjheaney/charles/index.html







      parent reply	other threads:[~2002-10-22 14:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-20 16:20 Array of unbounded strings, memory leakage? Eric G. Miller
2002-10-20 19:08 ` Jeffrey Carter
2002-10-20 20:16   ` Eric G. Miller
2002-10-22 14:36 ` Matthew Heaney [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