From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Tom Lord Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: About shared substrings Date: Fri, 16 Jan 2004 14:00:27 -0800 (PST) Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <200401162200.OAA06238@morrowfield.regexps.com> References: <1074242951.6739.5.camel@localhost> <1074285306.6739.178.camel@localhost> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1074290290 30502 80.91.224.253 (16 Jan 2004 21:58:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Jan 2004 21:58:10 +0000 (UTC) Cc: guile-user@gnu.org, guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jan 16 22:58:03 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 1Ahbyd-0005N6-00 for ; Fri, 16 Jan 2004 22:58:03 +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 1AhbtU-0006fu-Dt for guile-devel@m.gmane.org; Fri, 16 Jan 2004 16:52:44 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Ahbq8-0005me-3e for guile-devel@gnu.org; Fri, 16 Jan 2004 16:49:16 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Ahbpa-0005c8-IR for guile-devel@gnu.org; Fri, 16 Jan 2004 16:49:13 -0500 Original-Received: from [65.234.195.89] (helo=morrowfield.regexps.com) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AhbpZ-0005bC-6i; Fri, 16 Jan 2004 16:48:41 -0500 Original-Received: (from lord@localhost) by morrowfield.regexps.com (8.9.1/8.9.1) id OAA06238; Fri, 16 Jan 2004 14:00:27 -0800 (PST) (envelope-from lord@morrowfield.regexps.com) Original-To: orre@nada.kth.se In-reply-to: <1074285306.6739.178.camel@localhost> (message from Roland Orre on Fri, 16 Jan 2004 21:35:06 +0100) 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:3233 gmane.lisp.guile.user:2627 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3233 > From: Roland Orre > 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. How can this actually work? It ensures that SUBSTRING, while live, protects PARENT. I see that and it's _roughly_ what's wanted. But SUBSTRING is tagged as a string, no? When that key (the substring) is collected -- won't that lead to a bogus free of the substring data? (I'm looking at the 1.6.4 GC implementation. Apologies if things have changed in some significant way in 1.7) -t _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel