Low-level functions
type 'a tThe 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 tWeak.create nreturns a new weak array of lengthn. All the pointers are initially empty. RaiseInvalid_argumentifnis not comprised between zero andObj.Ephemeron.max_ephe_length(limits included).
val length : 'a t -> intWeak.length arreturns the length (number of elements) ofar.
val set : 'a t -> int -> 'a option -> unitWeak.set ar n (Some el)sets thenth cell ofarto be a (full) pointer toel;Weak.set ar n Nonesets thenth cell ofarto empty. RaiseInvalid_argument "Weak.set"ifnis not in the range 0 toWeak.lengtha - 1.
val get : 'a t -> int -> 'a optionWeak.get ar nreturns None if thenth cell ofaris empty,Some x(wherexis the value) if it is full. RaiseInvalid_argument "Weak.get"ifnis not in the range 0 toWeak.lengtha - 1.
val get_copy : 'a t -> int -> 'a optionWeak.get_copy ar nreturns None if thenth cell ofaris empty,Some x(wherexis a (shallow) copy of the value) if it is full. In addition to pitfalls with mutable values, the interesting difference withgetis thatget_copydoes not prevent the incremental GC from erasing the value in its current cycle (getmay delay the erasure to the next GC cycle). RaiseInvalid_argument "Weak.get"ifnis not in the range 0 toWeak.lengtha - 1.If the element is a custom block it is not copied.
val check : 'a t -> int -> boolWeak.check ar nreturnstrueif thenth cell ofaris full,falseif it is empty. Note that even ifWeak.check ar nreturnstrue, a subsequentWeak.getar ncan returnNone.
val fill : 'a t -> int -> int -> 'a option -> unitWeak.fill ar ofs len elsets toelall pointers ofarfromofstoofs + len - 1. RaiseInvalid_argument "Weak.fill"ifofsandlendo not designate a valid subarray ofa.
val blit : 'a t -> int -> 'a t -> int -> int -> unitWeak.blit ar1 off1 ar2 off2 lencopieslenweak pointers fromar1(starting atoff1) toar2(starting atoff2). It works correctly even ifar1andar2are the same. RaiseInvalid_argument "Weak.blit"ifoff1andlendo not designate a valid subarray ofar1, or ifoff2andlendo not designate a valid subarray ofar2.