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,b84f51b862b7b6f5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-09 11:50:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!newsstand.cit.cornell.edu!news.stealth.net!news.stealth.net!news.astraweb.com!news-small.astraweb.com!news-xfer.cox.net!cox.net!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!nntp.clear.net.nz!news.clear.net.nz.POSTED!not-for-mail NNTP-Posting-Date: Thu, 09 Jan 2003 13:50:49 -0600 From: Craig Carey Newsgroups: comp.lang.ada Subject: Re: String library with garbage collection? Date: Fri, 10 Jan 2003 08:50:53 +1300 Message-ID: References: X-Newsreader: Forte Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Organization: Customer of Mercury Telecommunications Ltd Cache-Post-Path: drone5.qsi.net.nz!unknown@tnt1-71.quicksilver.net.nz X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/) X-Original-NNTP-Posting-Host: drone5-svc-skyt.qsi.net.nz X-Original-Trace: 10 Jan 2003 08:50:46 +1300, drone5-svc-skyt.qsi.net.nz NNTP-Posting-Host: 203.97.37.6 X-Trace: sv3-y4V6P8zF+YRXXVJEgdZk2ATuO9/518yr8mUEXNIleibjwVtfD4yRV15Ax5qjxyVHV6YtgvtnVgX6Lb0!ALd+qmTkWft5P6DumQdSbZjqXTsQvOWeAY3hrdpJLZNsmQYeKvkg32LtFLX55ll2uyzjeMTqB/7g!WRImGg0= X-Complaints-To: Complaints to abuse@clear.net.nz X-DMCA-Complaints-To: Complaints to abuse@clear.net.nz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:32840 Date: 2003-01-10T08:50:53+13:00 List-Id: On Thu, 09 Jan 2003 11:33:56 +0100, Ingo "I. Marks" wrote: >I'm looking for an open source dynamic string library with garbage >collection for Ada95. > >Any hints? > I have a "faster than Unbounded Strings" strings package here: http://www.ijs.co.nz/code/ada95_strings_pkg.zip package StriUnli, 17KB, updated in Jan 2003, seems to run well. That package does not implement garbage collecting. Also it is not 'dynamic'. Each string has waste and a way of resolving that is to have the calling program shift it into global variables if possible. type V_Str is private; -- tagged private is possible ... type V_Str is new Ada.Finalization.Controlled with record Len : aliased Natural := 0; Str : -- pointer to a string on the heap ... end record; An example of the sort of code the package allows: S : V_Str Vssl (S) (Len (S) + 1 .. Vss (S)'Last) := Vss (S) (Z .. Len (S)); (Functions Vssl() and Vss() return pointers to the string on the heap.) Increasing the use of pointers increases the safeness of the program since slicing can causes SIGSEGV's in Windows 2000 when the number of tasks is increased by reducing the stack size. It is nice how a pointer can be dereferences on the left hand side of an assignment. Anyway maybe garbage was not needed. This argument might be one that is followed. 1. Program needs to run faster; 2. Timing tests pinpoint a problem with ":=" being slow (it is inevitable given the wording of RM7.6 which splits ":=" into 2 procedures (Finalize (which may deallocate) and Adjust (which may allocate))). 3. The solution is replace ":=" with a call to a user defined "Assign(L,R)". Using ":=" is nice but it is not the best option. All ":=" can be changed into calls to an "Assign()" proc. 4. Strings are on the heap. RM7.6's Finalize() seems efficient enough that automatic deallocation can be done instead having plain pointers to strings on the heap. 5. Still calls to "new" and deallocations are slow. Rather than have user side garbage collecting (something done to avoid garbage collecting by the OS, perhaps), a trick is to make the strings be globals. For example, each procedure can get a package of temporary strings as a parameter (which may make it task safe (RM9.10(11)). The global strings are renamed so that they look like local variables. HTTP_Buffer : V_Str renames Tmps.Str_1; If the number of globals is variable, then maybe a balanced binary tree could hold them (e.g. some code based on Booch's AVL binary tree code). 6. The strings have waste space that may diffuse throughout the global strings if fast swapping of strings was done. Modifying the algorithms could prevent a problem with that. 7. A task safe garbage collecting strings manager may be much slower than a scheme based on global variables if it uses protected objects to make it task safe. Anyway, if a garbage collecting scheme appears, it could be timed to see if it is any good. I presume it won't compare well in timing tests. It is not shown by here (or in the previous message) that there was a real need for a garbage collecting strings package. It could be quite hard to get it running fast enough. Craig Carey Ada 95 mailing lists http://www.ijs.co.nz/ada_95.htm