[GAP] unbounded strings package

Matthew Heaney matthewjheaney at earthlink.net
Thu Sep 22 15:32:17 CEST 2005


But a Finalize precedes the Adjust, so any deallocation would have already
been done by the time Adjust is called.  The order of events is:

finalize
copy
adjust


> -----Original Message-----
> From: gap-bounces at gnat.info [mailto:gap-bounces at gnat.info] On 
> Behalf Of Ted Baker
> Sent: Thursday, September 22, 2005 9:15 AM
> To: GNAT Academic Program discussion list
> Subject: [GAP] unbounded strings package
> 
> 
> In class, I used the package Ada.Strings.Unbounded as an 
> example of how to use controlled types.  I ran into a 
> surprise.  Am I blind, or does this leak storage?
> 
> S : Unbounded_String;
> ...
> S := S & 'c';
> 
> The Adjust procedure looks like this:
> 
> procedure Adjust (Object : in out Unbounded_String) is
> begin
>    --  Copy string, except we do not copy the statically 
> allocated null
>    --  string, since it can never be deallocated.
>    if Object.Reference /= Null_String'Access then
>       Object.Reference := new String'(Object.Reference.all);
>    end if;
> end Adjust;
> 
> I was expecting that it would free the old reference before 
> assigning the new one.
> 
> --Ted
> _______________________________________________
> GAP mailing list
> GAP at gnat.info
> /no-more-mailman.html
> To unsubscribe from this list, please contact the GAP GNAT 
> Tracker administrator within your organization.
> 



More information about the GAP mailing list