guile-weakref/README.org

18 lines
731 B
Org Mode
Raw Normal View History

2024-09-12 02:03:05 +00:00
* Guile Weak References
2024-09-12 01:59:02 +00:00
2024-09-12 02:32:20 +00:00
This is a simple little library that makes use of the weak vector functionality in core Guile
to implement weak references, objects which weakly point to other objects.
2024-09-12 01:59:02 +00:00
The interface is very simple:
(make-weakref obj)
- Create a weak reference, which will not count as a reference, so the object can be garbage collected
2024-09-12 02:04:09 +00:00
(weakref-object ref)
- Get the object associated with the reference, or #f if it has been garbage collected.
2024-09-12 01:59:02 +00:00
2024-09-12 02:03:05 +00:00
** Implementation
2024-09-12 02:32:20 +00:00
This is a very simple implementation (thanks David Thompson for a simpler idea). It simply calls a single-
element weak vector a weak reference. Initially this used the weak hash table support but using a weak
vector is far simpler and uses less memory.