From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Roland Orre Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: About shared substrings Date: Fri, 16 Jan 2004 21:35:06 +0100 Organization: Royal Institute of Technology Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <1074285306.6739.178.camel@localhost> References: <1074242951.6739.5.camel@localhost> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1074285893 20870 80.91.224.253 (16 Jan 2004 20:44:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Jan 2004 20:44:53 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jan 16 21:44:49 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Ahapk-0000Ps-00 for ; Fri, 16 Jan 2004 21:44:49 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AhamO-00006Z-LE for guile-devel@m.gmane.org; Fri, 16 Jan 2004 15:41:20 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Aham7-00005L-Ia for guile-devel@gnu.org; Fri, 16 Jan 2004 15:41:03 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AhalL-0008Er-IV for guile-devel@gnu.org; Fri, 16 Jan 2004 15:40:46 -0500 Original-Received: from [130.237.222.202] (helo=smtp.nada.kth.se) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1Ahakn-00082k-Kh; Fri, 16 Jan 2004 15:39:42 -0500 Original-Received: from c640 (h148n2fls33o875.telia.com [217.208.54.148]) (authenticated bits=0) by smtp.nada.kth.se (8.12.10/8.12.1) with ESMTP id i0GKdd88005074 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Fri, 16 Jan 2004 21:39:39 +0100 (MET) Original-To: guile-devel@gnu.org, guile-user@gnu.org In-Reply-To: X-Mailer: Ximian Evolution 1.4.5 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3230 gmane.lisp.guile.user:2622 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3230 Today I became really impressed. For me shared substrings was an essential feature of guile as this made me able to speed up pure scheme based reading of fixed width text files in a dramatic way as I only needed to declare a buffer and from this buffer allocate a set of substrings corresponding to the fields of that table. Using this scheme I didn't need to do any more memory allocations of substrings as every field was immediately accessible by standard scheme string conversion routines when the buffer was read. Now when I found that shared substrings were removed from guile 1.7 I first came up with a complicated scheme using guile_gc_protect_object but where I would have to do explicit deallocation of shared strings. I discussed this issue with Mikael Djurfeldt today and then he came up with the following solution: SCM substring_table; SCM scm_make_shared_substring (SCM parent, SCM start, SCM end) { SCM substring; char *mem; int c_start, c_end; SCM_VALIDATE_SUBSTRING_SPEC_COPY (1, parent, mem, 2, start, c_start, 3, end, c_end); substring = scm_cell (SCM_MAKE_STRING_TAG (c_end - c_start), (scm_t_bits) (mem + c_start)); scm_hash_set_x (substring_table, substring, parent); return substring; } where the following is put in the main: substring_table = scm_permanent_object (scm_make_weak_key_hash_table (SCM_UNDEFINED)); This is almost magical :) It works perfectly well and I don't need to bother about any explicit deallocation. This is also the first time I really understand the purpose of these weak hash tables. For weak hash tables the hash entry will be garbage collected first when the key is seen as garbage. With this scheme we still have the same essential functionality from my perspective about shared substrings but we do no longer need an explicit tag for shared substrings. Mikael Djurfeldt is relly the most clever programmer I know. Many thanks! Roland Orre _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel