From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,64b29dfa2220a59f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news.germany.com!newsfeed.stueberl.de!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!mutlu.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Reserve_Capacity for Unbounded_String? Date: Wed, 25 Jul 2007 07:07:07 +0100 Organization: Pushface Message-ID: References: <1185134043.892012.217560@n2g2000hse.googlegroups.com> <1185203238.701948.307410@m37g2000prh.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1185343628 6203 62.49.19.209 (25 Jul 2007 06:07:08 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 25 Jul 2007 06:07:08 +0000 (UTC) Cancel-Lock: sha1:ZFAnqqN0N+1ih6mqbfhokH2puHI= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) Xref: g2news2.google.com comp.lang.ada:1149 Date: 2007-07-25T07:07:07+01:00 List-Id: Robert A Duff writes: > It's the copy I'm wondering about, not the new and free so much. > To append N characters to an unb string requires quadratic copying > (copying a char N**2 / 2 times). > > If you double the allocation every time, it's amortized linear. > Yes, you waste some space that way. I made a limited Unbounded_String type (with an Append operation) that works this way when faced with a similar problem (I am stuck on a rather old GNAT which allocates every time). 30% performance improvement overall, as I recall.