Page 1 of 1

Is there a way to access the reference count information?

Posted: Tue Dec 07, 2010 7:45 pm
by npolyspace
I would like to have a large global data structure (possibly a hash table, but not necessarily). I would like to have many functions add things to the structure, and look for things in the structure, getting references to internal structures. I would like to be able to periodically "clean up my structure", removing whatever doesn't have any external references to it. Is this possible? Is there an easier way to do this?

Re: Is there a way to access the reference count information?

Posted: Tue Dec 07, 2010 8:15 pm
by Duke
npolyspace wrote:I would like to have a large global data structure (possibly a hash table, but not necessarily). I would like to have many functions add things to the structure, and look for things in the structure, getting references to internal structures. I would like to be able to periodically "clean up my structure", removing whatever doesn't have any external references to it. Is this possible? Is there an easier way to do this?
Interesting question. I don't suppose there's any hard restriction stopping you from doing your own reference counting (and you could read the source of $YOUR_LISP_IMPLEMENTATION for ideas on how to do that) but some (probably most) CL implementations already include garbage collection, so I doubt you'd want to implement it yourself.

I was curious, so I did some googling and found "weak hash tables" in the SBCL manual, which seemed like something that ought to exist, and which seems to solve your problem rather handily: http://www.sbcl.org/manual/Hash-Table-Extensions.html

Re: Is there a way to access the reference count information?

Posted: Tue Dec 07, 2010 9:28 pm
by nuntius
You're looking for "weak pointers". They are not in the CL standard, but most major CL implementations now have them. trivial garbage is a portability library that contains them.

Re: Is there a way to access the reference count information?

Posted: Wed Dec 08, 2010 4:32 am
by gugamilare
I would say for you to use "weak hash-tables". They are available in trivial-garbage.

Re: Is there a way to access the reference count information?

Posted: Thu Dec 09, 2010 2:18 pm
by Warren Wilkinson
Can you tell us more about your problem? Its hard to suggest any one solution without more detail.

Re: Is there a way to access the reference count information?

Posted: Fri Dec 10, 2010 6:56 pm
by npolyspace
I think that the weak hash tables is exactly what I was looking for. Thanks