Module Import0.Weak
Arrays of weak pointers and hash sets of weak pointers.
Low-level functions
- type 'a t
- The type of arrays of weak pointers (weak arrays). A weak pointer is a value that the garbage collector may erase whenever the value is not used any more (through normal pointers) by the program. Note that finalisation functions are run before the weak pointers are erased, because the finalisation functions can make values alive again (before 4.03 the finalisation functions were run after). - A weak pointer is said to be full if it points to a value, empty if the value was erased by the GC. - Notes: - Integers are not allocated and cannot be stored in weak arrays.
- Weak arrays cannot be marshaled using Stdlib.output_valuenor the functions of theMarshalmodule.
 
- val create : int -> 'a t
- Weak.create nreturns a new weak array of length- n. All the pointers are initially empty. Raise- Invalid_argumentif- nis not comprised between zero and- Obj.Ephemeron.max_ephe_length(limits included).
- val length : 'a t -> int
- Weak.length arreturns the length (number of elements) of- ar.
- val set : 'a t -> int -> 'a option -> unit
- Weak.set ar n (Some el)sets the- nth cell of- arto be a (full) pointer to- el;- Weak.set ar n Nonesets the- nth cell of- arto empty. Raise- Invalid_argument "Weak.set"if- nis not in the range 0 to- Weak.length- a - 1.
- val get : 'a t -> int -> 'a option
- Weak.get ar nreturns None if the- nth cell of- aris empty,- Some x(where- xis the value) if it is full. Raise- Invalid_argument "Weak.get"if- nis not in the range 0 to- Weak.length- a - 1.
- val get_copy : 'a t -> int -> 'a option
- Weak.get_copy ar nreturns None if the- nth cell of- aris empty,- Some x(where- xis a (shallow) copy of the value) if it is full. In addition to pitfalls with mutable values, the interesting difference with- getis that- get_copydoes not prevent the incremental GC from erasing the value in its current cycle (- getmay delay the erasure to the next GC cycle). Raise- Invalid_argument "Weak.get"if- nis not in the range 0 to- Weak.length- a - 1.- If the element is a custom block it is not copied. 
- val check : 'a t -> int -> bool
- Weak.check ar nreturns- trueif the- nth cell of- aris full,- falseif it is empty. Note that even if- Weak.check ar nreturns- true, a subsequent- Weak.get- ar ncan return- None.
- val fill : 'a t -> int -> int -> 'a option -> unit
- Weak.fill ar ofs len elsets to- elall pointers of- arfrom- ofsto- ofs + len - 1. Raise- Invalid_argument "Weak.fill"if- ofsand- lendo not designate a valid subarray of- a.
- val blit : 'a t -> int -> 'a t -> int -> int -> unit
- Weak.blit ar1 off1 ar2 off2 lencopies- lenweak pointers from- ar1(starting at- off1) to- ar2(starting at- off2). It works correctly even if- ar1and- ar2are the same. Raise- Invalid_argument "Weak.blit"if- off1and- lendo not designate a valid subarray of- ar1, or if- off2and- lendo not designate a valid subarray of- ar2.