mmap and IArray slices

Duncan Coutts duncan@coutts.uklinux.net
Sat, 26 Apr 2003 17:40:23 +0100


On Sat, 26 Apr 2003 12:21:52 -0400
David Roundy <droundy@abridgegame.org> wrote:

> I had a couple ideas, and I was wondering if they were good ones.
> 
> One is the idea of a slice function on an IArray:
> 
> a' = slice a (i,j) giving an array with the elements i..j of array a.
> 
	[..]
> I'm thinking that it may even be possible to make the GC smart enough
> to get rid of mother strings which are needed by very few children (at
> least if it's desperate), if array slices were supported at a low
> enough level... I imagine they'd have to be supported at a very low
> level.

Perhaps it could be done with cunning use of finalisers. Instead of
having the substrings keep references to the 'mother' string, you could
reverse it, so the mother keeps (weak?) references to the substrings.
That way, when the mother string is garbage collected it can make copies
of the substrings in new storage.

As you suggest, a further optimisation might be to not collect the
mother string if enough of it is still in use. Also when the substrings
are copied, you could try and do it in a way that maintains as much
sharing as possile if substrings overlap.

It porbably still requires significant low-level support by maybe you
don't have to teach the garbage collecter specially.

Duncan