This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: New shared substring implementation


forcer <forcer@mindless.com> writes:

> > > A solution to this problem would be to have (substring) mark the
> > > string it's applied to to be a "substring" as well. The problem
> > > then is that:
> > > (define str1 "foo")
> > > (define str2 (substring str1 2 3)) ; str1 and str2 are marked as
> > > 			           ; shared substrings
> > > (string-set! str1 0 #\b)	   ; str1 now points to a newly
> > > 				   ; malloc'd copy of the string,
> > > 				   ; and str2 points to the
> > > 				   ; original string[2]
> > > (string-set! str2 0 #\b)	   ; str2 is now a copy of the
> > > 				   ; string as well, and there's
> > > 				   ; no pointer to the original
> > > 				   ; string left :]
> > 
> > Hmm... Isn't this exactly what you want?
> > 
> > After the second string-set!, there's no reason to keep the original
> > string, so it should be freed.
> 
> Yes. The problem is, how to decide when it got to be freed. We
> need something like a reference count here :]

I'm lost.  As long as str2 is a substring object, there will be a
reference from that object to an object representing the original
string.  During GC, that reference will keep the string object alive.

When str2 is converted into a real string, that reference will
disappear, so that, now no-one is keeping the original string object
alive anymore and it will be GC'd.

To me, the hard problem seems to be how to mutate str1 into a shared
string object when it is subjected to the substring operation.  It
seems that if any shared substrings has been created from str1 before
this operation, they will end up having an "original string pointer"
pointing to a shared string object.  Maybe this could be solved by
mutating str1 into a shared string object the first time a shared
object is created from it?  Another idea would be to make it possible
for shared string objects to point to other shared string objects:
Operations on the shared string would follow the pointers all the way
to the original string and possibly mutate the object so that this
only needs to be done once.

Hmm...  One would like to find a solution with less overhead.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]