comp.lang.ada
 help / color / mirror / Atom feed
From: sjw <simon.j.wright@mac.com>
Subject: Re: Deallocation of Unbounded_String
Date: Sat, 25 Jul 2009 10:09:30 -0700 (PDT)
Date: 2009-07-25T10:09:30-07:00	[thread overview]
Message-ID: <407b6ec0-0e40-4ffe-a8a0-de475f1527ab@i6g2000yqj.googlegroups.com> (raw)
In-Reply-To: b3e58bec-89fe-4f8a-a4d8-470d618a3c65@b14g2000yqd.googlegroups.com

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.



  reply	other threads:[~2009-07-25 17:09 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 [this message]
2009-07-25 17:16   ` vlc
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