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: Re: About shared substrings (now working) Date: Mon, 19 Jan 2004 00:12:45 +0100 Organization: Royal Institute of Technology Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <1074467565.6733.300.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 1074468855 20950 80.91.224.253 (18 Jan 2004 23:34:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 18 Jan 2004 23:34:15 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 19 00:34:09 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 1AiMQj-0002Hv-00 for ; Mon, 19 Jan 2004 00:34:09 +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 1AiMQT-0006RN-8V for guile-devel@m.gmane.org; Sun, 18 Jan 2004 18:33:53 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AiMQF-0006PX-1R for guile-devel@gnu.org; Sun, 18 Jan 2004 18:33:39 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AiMFG-0000Us-Bl for guile-devel@gnu.org; Sun, 18 Jan 2004 18:22:49 -0500 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1AiMFG-0000Tx-3E; Sun, 18 Jan 2004 18:22:18 -0500 Original-Received: from [130.237.222.202] (helo=smtp.nada.kth.se) by mx20.gnu.org with esmtp (Exim 4.24) id 1AiMAm-0006yJ-LH; Sun, 18 Jan 2004 18:17:40 -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 i0INHW88027525 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Mon, 19 Jan 2004 00:17:33 +0100 (MET) Original-To: guile-user@gnu.org, guile-devel@gnu.org 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:3246 gmane.lisp.guile.user:2640 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3246 As Mikael Djurfeldt commented, his solution on Friday to the shared substring problem was a little too magical. I added his suggestion about guardians and that works fine. The essential code is below. Despite that I'm happy that I've got shared substrings working again in guile 1.7 and it's of course elegant to not need the substring tag, at the same time I also learned both about weak_hash_tables and guardians, I have to say that I'm somewhat disappointed with the guile developers just removing an essential function like this, before providing an alternative. The reason I have used shared substrings is because of the side effects. I was very happy when the make-shared-substring function was introduced in 93 or 94. This made it possible for me to make tremendous speedups when reading fix length text records and be able to immediately treat the different fields of each record with scheme standard conversion routines. Of course our production environment is mostly using specialized C-functions for this, but some essential parts of our production code is still based upon shared substrings as well as the prototype environment of course. When reading many millions of records from a fix width text file it makes a tremendous difference in speed if you can avoid substring allocation to reach the fields of these records and it is also nice to be able to access every field with standard scheme routines. During the fall 2003 I was not following the guile-devel list as I mainly consider myself as a guile user. The removal of make-shared-substring was not mentioned at all on the guile-user list as I'm aware about. In the comments from 1.6 about make-shared-substring being deprecated I understood that it would be replaced with implicitly shared substrings in 1.7. OK, 1.7 is a development version so I should not count on the functions there, this is my mistake. Anyway, here is the working code (the gc-hook is not necessary, therefore commented, as the unused substrings will be cached in the guardian (OK, that was Mikael Djurfeldt genius again :)) Hmm, maybe this is getting closer to the future "substring" as well :) (at least for us who want the side effects...) Best regards Roland Orre SCM substring_table; SCM substring_guardian; static void * substrings_zombify (void *dummy1 SCM_UNUSED, void *dummy2 SCM_UNUSED, void *dummy3 SCM_UNUSED) { SCM rest,str; str=scm_call_0(substring_guardian); while (SCM_STRINGP(str)) { SCM_SETCAR(str,SCM_EOL); SCM_SETCDR(str,SCM_EOL); str=scm_call_0(substring_guardian); } return 0; } /* substrings_zombify */ SCM_DEFINE (scm_make_shared_substring, "make-shared-substring", 1, 2, 0, (SCM parent, SCM start, SCM end), "Return a shared substring of @var{str}. The arguments are the\n" "same as for the @code{substring} function: the shared substring\n" "returned includes all of the text from @var{str} between\n" "indexes @var{start} (inclusive) and @var{end} (exclusive). If\n" "@var{end} is omitted, it defaults to the end of @var{str}. The\n" "shared substring returned by @code{make-shared-substring}\n" "occupies the same storage space as @var{str}.") #define FUNC_NAME s_scm_make_shared_substring { 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_call_0 (substring_guardian); if (SCM_FALSEP(substring)) substring = scm_cell(SCM_MAKE_STRING_TAG (c_end - c_start), (scm_t_bits) (mem + c_start)); else { SCM_DEFER_INTS; SCM_SETCAR(substring,SCM_MAKE_STRING_TAG (c_end - c_start)); SCM_SETCDR(substring,(scm_t_bits) (mem + c_start)); SCM_ALLOW_INTS; } scm_hash_set_x (substring_table, substring, parent); scm_apply (substring_guardian,substring,scm_listofnull); return substring; } #undef FUNC_NAME /* in init */ substring_table = scm_permanent_object(scm_make_weak_key_hash_table(SCM_UNDEFINED)); substring_guardian = scm_permanent_object(scm_make_guardian(SCM_UNDEFINED)); // scm_c_hook_add(&scm_after_gc_c_hook, substrings_zombify,0,0); _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel