comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Reserve_Capacity for Unbounded_String?
Date: Mon, 23 Jul 2007 20:01:17 -0500
Date: 2007-07-23T20:01:17-05:00	[thread overview]
Message-ID: <f83ish$p8o$1@jacob-sparre.dk> (raw)
In-Reply-To: 1185203238.701948.307410@m37g2000prh.googlegroups.com


"Adam Beneschan" <adam@irvine.com> wrote in message
news:1185203238.701948.307410@m37g2000prh.googlegroups.com...
...
> > Is this a reasonable approach if performance is of concern?
>
> I sure wouldn't count on this.

I second (or is that "third") Adam and Jeff's comments.

For Janus/Ada, Unbounded_String is just a controlled wrapper around "access
String"; in particular, the length is the length of the item allocated. The
code you have would just cause an extra allocation/deallocation without any
corresponding benefit (and it might even cause additional fragmentation and
slow the program down).

In general, you cannot depend on the performance of the predefined packages;
you can presume that implementations have done a decent job for their
target, but that is about all. (The containers are a bit of an exception, in
that there are performance requirements on them; but those requirements are
vague enough to be pretty meaningless for average-sized containers.)

I usually recommend to use the predefined packages as necessary in your
application, and avoid worrying about performance of them. If it turns out
that there is a performance problem, and that problem is with the one of the
predefined packages, then it makes sense to replace the offending package
with something custom-written to match the problem at hand. (In this case,
just using type String and doing your own storage management would seem to
be appropriate.)

For things like Unbounded_Strings (and the Containers), the main value is to
let the package do the memory management (meaning that you have well-tested
memory management that won't leak or break). Trying to take over some of
that is suspicious (that's true for Reserve_Capacity in the containers as
well), because it is easy to get it wrong and cause *worse* performance.

In any case, implementing Reserve_Capacity to do anything (as opposed to
being a no-op) in Janus/Ada would require junking the entire existing
implementation and starting over. It surely would add overhead (because
you'd continually need to check the allocated length against the "nominal"
length). As such, this is something I would fight strongly.

                                 Randy.






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