comp.lang.ada
 help / color / mirror / Atom feed
From: Pascal Obry <pascal@obry.net>
To: Randy Brukardt <randy@rrsoftware.com>
Subject: Re: Reserve_Capacity for Unbounded_String?
Date: Wed, 25 Jul 2007 01:54:30 +0200
Date: 2007-07-25T01:54:43+02:00	[thread overview]
Message-ID: <46A69136.3010803@obry.net> (raw)
In-Reply-To: <f85i0u$jsl$1@jacob-sparre.dk>

Randy Brukardt a �crit :
> Maybe some uninformed users, but not anyone who doesn't add non-existent
> requirements to the specs.
> 
> Unbounded_String is best used for storage (not calculation) of values. It is
> a horrible design for calculation, no matter what schemes you use for the
> implementation.
> 
> Moreover, I've yet to see an example where the performance of
> Unbounded_Strings (allocation-wise) matters. Our spam filter was written
> solely using Unbounded_Strings, it does a lot of calculation (normalization
> of e-mail) and still the allocation overhead is insignificant. (The
> bottleneck is in Index, which does no allocation at all.)
> 
> I can imagine that it would be possible to write a program where the
> allocation overhead would matter, but such a program would be helped a lot
> more by avoiding Unbounded_Strings (and *all* of their allocation overhead)
> than by tweaking the implementation of Unbounded_Strings to reduce that
> overhead in a few rarely used operations.
> 
> So I stand by my original statement. Anyone that depends on the performance
> characteristics of a particular implementation (of anything!) is an idiot
> and will be burned in the future.

Well Randy, its all too easy to dismiss points like this by saying that
you have not seen a problem with the current implementation and if
somebody show you something wrong in this area then he has to use
something else that Unbounded_String... At least that's the way I'm
reading your message.

Just try this on your implementation:

   C : constant Character := 'x';

   U : Unbounded_String;

   for k in 1 .. 5_000_000 loop
      U := U & C;
   end loop;

And then test it with GNAT. Of course that is not a real example but
very close to something done in my templates engine.

You were speaking about performance about checking the preallocated
buffer. My point is that it is not that costly compared to the price of
reallocating a whole string thousands of time.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



  parent reply	other threads:[~2007-07-24 23:54 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
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 [this message]
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