Module Weak_array

Module for dealing with weak pointers, i.e., pointers that don't prevent garbage collection of what they point to.

This module is like the OCaml standard library module of the same name, except that it requires that the values in the weak set are heap blocks.

type 'a t
val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val create : len:Base.int -> _ t @@ portable
val length : _ t -> Base.int @@ portable
val set : 'a t -> Base.int -> 'a Heap_block.t Base.option -> Base.unit @@ portable
val set_exn : 'a t -> Base.int -> 'a Base.option -> Base.unit @@ portable

set_exn raises an exception if given Some x with x not being a heap block. This is in addition to raising exceptions on bounds violation as set does.

val get : 'a t -> Base.int -> 'a Heap_block.t Base.option @@ portable
val is_some : _ t -> Base.int -> Base.bool @@ portable
val is_none : _ t -> Base.int -> Base.bool @@ portable
val iter : 'a t -> f:('a -> Base.unit) -> Base.unit @@ portable
val iteri : 'a t -> f:(Base.int -> 'a -> Base.unit) -> Base.unit @@ portable
val blit : src:'a t -> src_pos:Base.int -> dst:'a t -> dst_pos:Base.int -> len:Base.int -> Base.unit @@ portable

blit is generally preferred over get followed by set because, unlike get, it doesn't have to make the value strongly-referenced. Making a value strongly-referenced, even temporarily, may result in delaying its garbage collection by a whole GC cycle.