[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About shared substrings

From: Mikael Djurfeldt
Subject: Re: About shared substrings
Date: Fri, 16 Jan 2004 16:54:51 -0500
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Roland Orre <address@hidden> 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;
>                                     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

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...  :)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]