| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A weak pointer is a reference to an object that doesn't prevent
the object from being garbage-collected.
Gauche provides weak pointers as a weak vector object.
A weak vector is like a vector of objects, except each object
can be garbage collected if it is not referenced from objects
other than weak vectors. If the object is collected, the
entry of the weak vector is replaced for #f.
gosh> (define v (make-weak-vector 1)) v gosh> (weak-vector-ref v 0) #f gosh> (weak-vector-set! v 0 (cons 1 1)) #<undef> gosh> (weak-vector-ref v 0) (1 . 1) gosh> (gc) #<undef> gosh> (gc) #<undef> gosh> (weak-vector-ref v 0) #f |
<sequence> and <collection>,
so you can use
gauche.collection (See section 9.3 gauche.collection - Collection framework) and
gauche.sequence (See section 9.18 gauche.sequence - Sequence framework).
(coerce-to <weak-vector> '(1 2 3 4)) => a weak vector with four elements |
By default, weak-vector-ref signals an error if k is
negative, or greater than or equal to the size of wvec.
However, if an optional argument fallback is given,
it is returned for such case.
With gauche.sequence module,
you can also use a method ref.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |