comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Reserve_Capacity for Unbounded_String?
Date: Mon, 23 Jul 2007 08:07:18 -0700
Date: 2007-07-23T08:07:18-07:00	[thread overview]
Message-ID: <1185203238.701948.307410@m37g2000prh.googlegroups.com> (raw)
In-Reply-To: <1185134043.892012.217560@n2g2000hse.googlegroups.com>

On Jul 22, 12:54 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> Why there is no Reserve_Capacity for Unbounded_String?
> Sounds like a natural idea to me.
>
> How to emulate it?
>
> The following seems to work fine:
>
> declare
>    S : Unbounded_String;
>    My_Capacity : constant := 1000;
> begin
>    S := To_Unbounded_String (My_Capacity);
>    Delete (Source => S, From => 1, Through => My_Capacity);
>    -- ...
> end;
>
> "Seems to work fine" means that after the above two operations the
> string is logically empty, but the subsequent appends run faster
> (which is actually the original motivation).
>
> Is this a reasonable approach if performance is of concern?

I sure wouldn't count on this.  I don't know what compiler you're
using or how it implements Unbounded_String; but just based on what I
know about how this package *might* be implemented and about the
suggested implementation in the Rationale, the performance
improvements you're seeing could be just an accident.  (One test: try
doing something like "Intp := new Integer;" after each append.  If the
Delete actually deallocates memory, and a piece of that memory could
be reused by a "new Integer" allocation, you may get very different
performance results than if the deallocated memory is never reused
except by new appends.  Here, though, I'm just guessing, since as I
said I have no idea how Unbounded_Strings is implemented.)

I'm with Jeff here: you may need an Unbounded_Strings package tailored
to your specific needs.  It just isn't possible to write a package
that will achieve the best performance for all programs that might
want to use it; even a simple idea like "Reserve_Capacity" could
introduce some implementation overhead that might be unwelcome in
programs that wouldn't benefit from that feature.

                           -- Adam






  parent reply	other threads:[~2007-07-23 15:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-22 19:54 Reserve_Capacity for Unbounded_String? Maciej Sobczak
2007-07-22 21:32 ` Robert A Duff
2007-07-23 19:29   ` Maciej Sobczak
2007-07-23 20:30     ` Robert A Duff
2007-07-23  4:28 ` Jeffrey R. Carter
2007-07-23 15:07 ` Adam Beneschan [this message]
2007-07-24  1:01   ` Randy Brukardt
2007-07-24  7:57     ` Pascal Obry
2007-07-24 18:58       ` Randy Brukardt
2007-07-24 23:50         ` Robert A Duff
2007-07-25  0:00           ` Randy Brukardt
2007-07-24 23:54         ` Pascal Obry
2007-07-25  0:52           ` Randy Brukardt
2007-07-25  1:28           ` Randy Brukardt
2007-07-25  7:48             ` Pascal Obry
2007-07-25  9:55               ` Georg Bauhaus
2007-07-25 10:02                 ` Georg Bauhaus
2007-07-25 18:58               ` Randy Brukardt
2007-07-25  8:50             ` Martin Krischik
2007-07-25  9:26               ` AW: " Grein, Christoph (Fa. ESG)
2007-07-25 15:32                 ` Martin Krischik
2007-07-25 15:39                 ` Martin Krischik
2007-07-24 23:41     ` Robert A Duff
2007-07-25  0:16       ` Randy Brukardt
2007-07-25  2:25         ` Robert A Duff
2007-07-25  6:07           ` Simon Wright
2007-07-25 19:08           ` Randy Brukardt
2007-07-25 20:37             ` Maciej Sobczak
2007-07-25 22:06               ` Georg Bauhaus
2007-07-26  6:24                 ` Maciej Sobczak
2007-07-26  8:09                   ` Dmitry A. Kazakov
2007-07-26  8:20                     ` Pascal Obry
2007-07-26  9:59                       ` Dmitry A. Kazakov
2007-07-26  8:35                   ` Georg Bauhaus
2007-07-26 22:11               ` Randy Brukardt
replies disabled

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