From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: About shared substrings Date: Fri, 16 Jan 2004 16:54:51 -0500 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: References: <1074242951.6739.5.camel@localhost> <1074285306.6739.178.camel@localhost> Reply-To: djurfeldt@nada.kth.se NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1074290353 30602 80.91.224.253 (16 Jan 2004 21:59:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Jan 2004 21:59:13 +0000 (UTC) Cc: guile-user@gnu.org, djurfeldt@nada.kth.se, guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jan 16 22:59:06 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 1Ahbzd-0005PZ-01 for ; Fri, 16 Jan 2004 22:59:05 +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 1Ahbym-0007D2-RK for guile-devel@m.gmane.org; Fri, 16 Jan 2004 16:58:12 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Ahbye-0007CY-Ng for guile-devel@gnu.org; Fri, 16 Jan 2004 16:58:04 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Ahby8-000780-T7 for guile-devel@gnu.org; Fri, 16 Jan 2004 16:58:03 -0500 Original-Received: from [213.212.20.77] (helo=kvast.blakulla.net) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Ahbvf-0006wu-6n; Fri, 16 Jan 2004 16:54:59 -0500 Original-Received: from chunk.mit.edu ([18.42.2.92] helo=chunk ident=Debian-exim) by kvast.blakulla.net with esmtp (Exim 3.36 #1 (Debian)) id 1AhbvY-0001Yl-00; Fri, 16 Jan 2004 22:54:52 +0100 Original-Received: from mdj by chunk with local (Exim 4.30) id 1AhbvX-00025u-Su; Fri, 16 Jan 2004 16:54:51 -0500 Original-To: Roland Orre In-Reply-To: <1074285306.6739.178.camel@localhost> (Roland Orre's message of "Fri, 16 Jan 2004 21:35:06 +0100") User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) 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:3234 gmane.lisp.guile.user:2628 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3234 Roland Orre writes: > 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 :) Unfortunately, it *is* magical. In addition, it is necessary to hand the newly created substring to a guardian. If we then add a hook function to some suitable GC hook which loops through all unreferenced substrings and sets their address pointer to NULL, everything should work. If we *don't* do that, the same area of memory will be freed repeatedly, which is not optimal. > Mikael Djurfeldt is relly the most clever programmer I know. Many thanks for the kind words! Yes, I am usually a blazing genius. My mistake above must certainly be due to something in my coffee or so... :) M _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel