comp.lang.ada
 help / color / mirror / Atom feed
From: Andy Askey <askeya@res.raytheon.com>
Subject: Re: Unbounded string deallocation
Date: 1999/08/26
Date: 1999-08-26T12:45:47+00:00	[thread overview]
Message-ID: <37C54509.17E067C1@res.raytheon.com> (raw)
In-Reply-To: 7q1tff$1n9$1@cnn.Princeton.EDU

Martin,
Thanx for the info.  My unbound string never goes out of scope until I
terminate my program (which is why I "thought" needed to deallocate it
myself).  If all I have to do to reclaim the memory is to create a new
string using the same variable, then this takes care of all my
problems.  Just to make sure I understand this correctly:

my_string : ada.strings.unbounded_string;
begin

  -- grab approx 1024 bytes of memory
  my_string := new ada.strings.unbounded_string.To_Unbound_String(1024);

  -- give back the 1024 bytes and grab 2048 new memory bytes
  my_string := new ada.strings.unbounded_string.To_Unbound_String(2048);

end

Is this correct.  I know am being simplistic with the actually memory
bytes allocated. But do I have the theory correct?

Thanx.
Andy


"Martin C. Carlisle" wrote:
> 
> Actually, the great thing about Ada.Strings.Unbounded is that the
> LRM requires it not to leak memory.  See LRM A.4.5(88).
> This means that when an unbounded string is reassigned, or goes out of
> scope, the memory will be reclaimed.
> 
> To use it for a brief period of time, use a declare block.
> 
> --Martin
> 
> In article <37C46FD4.A42CC1A1@res.raytheon.com>,
> Andy Askey  <askeya@res.raytheon.com> wrote:
> >I am looking into using Ada.Strings.Unbounded for dynamically creating
> >temporary storage of character arrays.  When I am finished processing
> >the string, I want to deallocate it.  I found a "Free" routine in the
> >spec but this uses a pointer to STRING and not UNBOUNDED_STRING.
> >
> >From the Apex ada.strings.unbounded.1.ada =>
> >
> > type Unbounded_String is private;
> > type String_Access is access all String;
> > procedure Free (X : in out String_Access);
> >
> >Can anyone help me out with the deallocation?  Anyone have a better idea
> >for dynamically allocating and deallocating memory for a small to medium
> >size byte array?
> >
> >Thanx.
> >--
> >---------------------------------------------------
> >|                 Andy Askey                      |
> >|              Software Engineer                  |
> >|           Raytheon Systems Company              |
> >|   670 Discovery Drive, Huntsville, AL  35806    |
> >|   Phone: (256) 971-2367  Fax: (256) 971-2306    |
> >|        andrew_j_askey@res.raytheon.com          |
> >---------------------------------------------------
> 
> --
> Martin C. Carlisle, Asst Prof of Computer Science, US Air Force Academy
> carlislem@acm.org, http://www.usafa.af.mil/dfcs/bios/carlisle.html
> DISCLAIMER:  This content in no way reflects the opinions, standards or
> policy of the US Air Force Academy or the United States Government.

-- 
---------------------------------------------------
|                 Andy Askey                      |
|              Software Engineer                  |
|           Raytheon Systems Company              |
|   670 Discovery Drive, Huntsville, AL  35806    |
|   Phone: (256) 971-2367  Fax: (256) 971-2306    |
|        andrew_j_askey@res.raytheon.com          |
---------------------------------------------------




  reply	other threads:[~1999-08-26  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-25  0:00 Unbounded string deallocation Andy Askey
1999-08-25  0:00 ` Martin C. Carlisle
1999-08-26  0:00   ` Andy Askey [this message]
1999-08-26  0:00     ` David C. Hoos, Sr.
1999-08-26  0:00     ` Andy Askey
1999-08-26  0:00     ` Martin C. Carlisle
     [not found]     ` <37c552fd@news1.us.ibm.net>
1999-08-26  0:00       ` Marin David Condic
1999-08-29  0:00         ` Robert Dewar
1999-08-30  0:00           ` Marin David Condic
1999-08-30  0:00             ` Robert Dewar
1999-08-26  0:00       ` Michael F. Yoder
1999-08-26  0:00   ` Pascal Obry
1999-08-26  0:00 ` David C. Hoos, Sr.
1999-08-30  0:00 ` Andy Askey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox