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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,76ec5d55630beb71 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-13 07:20:31 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: Ada 200X Date: 13 Jun 2003 07:20:31 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0306130620.1d7a456a@posting.google.com> References: <3EDC0BE6.42300129@somewhere.nil> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1055514031 12721 127.0.0.1 (13 Jun 2003 14:20:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 13 Jun 2003 14:20:31 GMT Xref: archiver1.google.com comp.lang.ada:39118 Date: 2003-06-13T14:20:31+00:00 List-Id: Craig Carey wrote in message news:... > > > Those packages are here: > http://home.earthlink.net/~matthewjheaney/charles/ > http://www.ijs.co.nz/code/ada95_strings_pkg.zip (19KB > > My strings package was intended to to be fast and open. > Mr H's need not be fast (but may be). The idealism includes that of > having functions return a private type (implying slicing is hidden > in the package). You can optimize string manipulation by using Resize to preallocate the internal buffer to a specified size, and by using To_Access to return a pointer to the internal buffer, which eliminates copying. The To_String and Slice operations return type String, so of course this will construct a temporary. If this is an issue, then use To_Access to get a pointer to the internal buffer, and then slice that directly: procedure Op (SC : String_Container_Subtype) is Slow : String := Slice (SC, Low => 10, High => 42); Fast : String renames To_Access (SC) (10 .. 42); begin > The Charles code resizes strings using a factor of 2.0 (i.e. 100%). > I used 1.70 (70%) after some testing (in Windows 2000). Again, by using Resize you can choose the exact size you prefer for the internal buffer. As a matter of fact, you could create a pool of string containers, each of which have different internal sizes, and then use Swap to swap in an internal buffer having the size you need. This would eliminate string buffer allocation entirely. For the pool you could use a map or set, which is ordered by internal buffer size. Finding a buffer would only require O (log n) in the worst case. http://home.earthlink.net/~matthewjheaney/charles/