Is there a way to access the reference count information?

Discussion of Common Lisp
Post Reply
npolyspace
Posts: 8
Joined: Wed Mar 17, 2010 6:03 pm

Is there a way to access the reference count information?

Post by npolyspace » Tue Dec 07, 2010 7:45 pm

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?

Duke
Posts: 38
Joined: Sat Oct 17, 2009 10:40 pm
Contact:

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

Post by Duke » Tue Dec 07, 2010 8:15 pm

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
"If you want to improve, be content to be thought foolish and stupid." -Epictetus

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

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

Post by nuntius » Tue Dec 07, 2010 9:28 pm

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.

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

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

Post by gugamilare » Wed Dec 08, 2010 4:32 am

I would say for you to use "weak hash-tables". They are available in trivial-garbage.

Warren Wilkinson
Posts: 117
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta
Contact:

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

Post by Warren Wilkinson » Thu Dec 09, 2010 2:18 pm

Can you tell us more about your problem? Its hard to suggest any one solution without more detail.
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

npolyspace
Posts: 8
Joined: Wed Mar 17, 2010 6:03 pm

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

Post by npolyspace » Fri Dec 10, 2010 6:56 pm

I think that the weak hash tables is exactly what I was looking for. Thanks

Post Reply