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: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!fdn.fr!club-internet.fr!feedme-small.clubint.net!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: Mon, 23 Jul 2007 20:01:17 -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 1185238737 25880 69.95.181.76 (24 Jul 2007 00:58:57 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 24 Jul 2007 00:58:57 +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: g2news1.google.com comp.lang.ada:16576 Date: 2007-07-23T20:01:17-05:00 List-Id: "Adam Beneschan" 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.