Is there a way to access the reference count information?
-
- Posts: 8
- Joined: Wed Mar 17, 2010 6:03 pm
Is there a way to access the reference count information?
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?
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.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?
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
Re: Is there a way to access the reference count information?
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.
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: Is there a way to access the reference count information?
I would say for you to use "weak hash-tables". They are available in trivial-garbage.
-
- 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?
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.
-
- Posts: 8
- Joined: Wed Mar 17, 2010 6:03 pm
Re: Is there a way to access the reference count information?
I think that the weak hash tables is exactly what I was looking for. Thanks