comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Random Input-Size and recognizing ENTER-press
Date: Sun, 19 Dec 2004 23:47:23 GMT
Date: 2004-12-19T23:47:23+00:00	[thread overview]
Message-ID: <fqoxd.4755$RH4.428@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <uis6yxok8.fsf@obry.net>

Pascal Obry wrote:

> That's not right. There is a buffer that is allocated when there is no more
> space into an Unbounded_String. So there is far less that N allocation when
> adding N characters into an Unbounded_String.

Here's what I have:

    Null_String : aliased String := "";

    function To_Unbounded (S : String) return Unbounded_String
      renames To_Unbounded_String;

    type Unbounded_String is new AF.Controlled with record
       Reference : String_Access := Null_String'Access;
    end record;

    procedure Append
      (Source   : in out Unbounded_String;
       New_Item : in Character)
    is
       S_Length : constant Integer := Source.Reference.all'Length;
       Length   : constant Integer := S_Length + 1;
       Tmp      : String_Access;

    begin
       Tmp := new String (1 .. Length);
       Tmp (1 .. S_Length) := Source.Reference.all;
       Tmp (S_Length + 1) := New_Item;
       Free (Source.Reference);
       Source.Reference := Tmp;
    end Append;

Starting with a null string, that certainly looks like N allocations.

-- 
Jeff Carter
"I was hobbling along, minding my own business, all of a
sudden, up he comes, cures me! One minute I'm a leper with
a trade, next minute my livelihood's gone! Not so much as a
'by your leave!' You're cured, mate. Bloody do-gooder!"
Monty Python's Life of Brian
76



  reply	other threads:[~2004-12-19 23:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-19  8:44 Random Input-Size and recognizing ENTER-press xadian
2004-12-19 14:50 ` Marius Amado Alves
2004-12-19 16:01   ` Jeffrey Carter
2004-12-19 16:03     ` Pascal Obry
2004-12-19 23:47       ` Jeffrey Carter [this message]
2004-12-20 14:36     ` Steve
2004-12-20 23:45       ` Jeffrey Carter
2004-12-19 15:52 ` Jeffrey 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