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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!postnews.google.com!o61g2000hsh.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Reserve_Capacity for Unbounded_String? Date: Wed, 25 Jul 2007 13:37:24 -0700 Organization: http://groups.google.com Message-ID: <1185395844.104043.194340@o61g2000hsh.googlegroups.com> References: <1185134043.892012.217560@n2g2000hse.googlegroups.com> <1185203238.701948.307410@m37g2000prh.googlegroups.com> NNTP-Posting-Host: 85.0.254.211 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1185395844 29561 127.0.0.1 (25 Jul 2007 20:37:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Jul 2007 20:37:24 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: o61g2000hsh.googlegroups.com; posting-host=85.0.254.211; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1185 Date: 2007-07-25T13:37:24-07:00 List-Id: On 25 Lip, 21:08, "Randy Brukardt" wrote: > > If you double the allocation every time, it's amortized linear. > > Yes, you waste some space that way. > > Quadratic allocation maximizes heap fragmentation Then instead of doubling the allocation use any multiplier that is smaller than 1.618 (yes, the golden ratio). 1.5 seems to be easy choice. Building a string by appending small chunks to the end seems to be a common practice. Optimizing the library for this case is a wise implementation strategy. > I still don't think it is worth it, but obviously a customer example could > change my mind. What about a customer who is choosing the competing product? Doesn't sound convincing enough? -- Maciej Sobczak http://www.msobczak.com/