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 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!news1.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!138.195.8.3.MISMATCH!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Reserve_Capacity for Unbounded_String? Date: Tue, 24 Jul 2007 19:16:15 -0500 Organization: Jacob's private Usenet server Message-ID: References: <1185134043.892012.217560@n2g2000hse.googlegroups.com> <1185203238.701948.307410@m37g2000prh.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1185322435 17119 69.95.181.76 (25 Jul 2007 00:13:55 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 25 Jul 2007 00:13:55 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1896 Xref: g2news2.google.com comp.lang.ada:1143 Date: 2007-07-24T19:16:15-05:00 List-Id: "Robert A Duff" wrote in message news:wccr6mx5pz0.fsf@shell01.TheWorld.com... > "Randy Brukardt" writes: ... > > For Janus/Ada, Unbounded_String is just a controlled wrapper around "access > > String"; in particular, the length is the length of the item > > allocated. > > Are you saying that: > > for I in 1..N loop > Append (Some_Unbounded_String, 'x'); > > causes a free and a "new" and a copy every time around the loop? Yup; I just checked the code to make sure. Moreover, I have yet to see an real example where the performance difference would matter that much (Free and new aren't that expensive relative to the alternatives). Our spam filter does operations like this, and as I said earlier, the performance bottleneck is with Index and with the file I/O operations and not here. (Nor are there any fragmentation problems that I can detect; the program runs for many days without issues.) In any case, I would expect this operation (of making the string longer) to do a lot of allocations anyway, because the string will need to be expanded a lot. And any "over"-allocation will be wasteful of memory; for the spam filter, that would tend to reduce the maximum size of messages that could be filtered.(Janus/Ada always emphasizes smaller memory usages versus wasting memory to get better performance.) Besides, in Janus/Ada, most the alternatives would also do a (under the covers) "new" and "free". We do try to optimize those out, but by default Var : String := Some_Value & 'x'; would generate three allocations and deallocations. The optimizer probably would get rid of the descriptors or allocate them statically, but the object Var probably would end up in the heap. If performance is a real issue, you'd have to write your own code to do the actual operations you want; for instance, in your example To_Unbounded_String (Some_Unbounded_String, (1..N => 'x')); would be a lot faster on any compiler (far fewer calls to a library; even if there is no allocation, there still will be overhead checks for bounds and the like). The examples where an alternative implementation of Unbounded_Strings would make a significant difference such that the application was fast enough with it and not fast enough without it have to be extremely rare. Randy.