comp.lang.ada
 help / color / mirror / Atom feed
From: vlc <just.another.spam.account@googlemail.com>
Subject: Re: Deallocation of Unbounded_String
Date: Sat, 25 Jul 2009 10:16:52 -0700 (PDT)
Date: 2009-07-25T10:16:52-07:00	[thread overview]
Message-ID: <8f0f5ced-6596-49bd-a433-e08643aaca6a@y19g2000yqy.googlegroups.com> (raw)
In-Reply-To: 407b6ec0-0e40-4ffe-a8a0-de475f1527ab@i6g2000yqj.googlegroups.com

On Jul 25, 7:09 pm, sjw <simon.j.wri...@mac.com> wrote:
> On Jul 25, 5:37 pm, vlc <just.another.spam.acco...@googlemail.com>
> wrote:
>
> > when using Unbounded_String, is it necessary to deallocate instances
> > of Unbounded_String after use or is there a kind of garbage collector
> > implemented?
>
> Unbounded_Strings are controlled, and look after their own memory when
> they go out of scope or are overwritten.
>
> If you had a variable currently holding a really huge unbounded string
> which you needed to keep in scope you could free its memory by saying
>
>    My_Unbounded_String := Ada.Strings.Unbounded.Null_Unbounded_String;
>
> > There is a "Free" function in Ada.Strings.Unbounded, but it takes an
> > access to String as argument, not an access to Unbounded_String.
>
> Hadn't noticed that; no idea why it's there (might be some use in
> Ada.Strings.Fixed?)
>
> > If I'm supposed to use this "Free" function to deallocate the memory
> > of my unused Unbounded_String, what is the correct usage of this
> > function (typecast of "access Unbounded_String" to "access String")?
>
> Very Bad Things would happen if you did this. The memory layout of the
> two types of object is going to be entirely different. An
> Unbounded_String is likely to be chained through a list of objects to
> be finalized when the scope is left - you interfere with that sort of
> construct at your peril.

Thanks a lot for your help!



  reply	other threads:[~2009-07-25 17:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-25 16:37 Deallocation of Unbounded_String vlc
2009-07-25 17:09 ` sjw
2009-07-25 17:16   ` vlc [this message]
2009-07-25 17:18 ` Yannick Duchêne Hibou57
2009-07-25 19:17 ` Jeffrey R. Carter
replies disabled

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