1Weak(3)                          OCaml library                         Weak(3)
2
3
4

NAME

6       Weak - Arrays of weak pointers and hash tables of weak pointers.
7

Module

9       Module   Weak
10

Documentation

12       Module Weak
13        : sig end
14
15
16       Arrays of weak pointers and hash tables of weak pointers.
17
18
19
20
21
22
23
24
25       === Low-level functions ===
26
27       type 'a t
28
29
30       The type of arrays of weak pointers (weak arrays).  A weak pointer is a
31       value that the garbage collector may erase at any time.  A weak pointer
32       is  said  to  be  full  if it points to a value, empty if the value was
33       erased by the GC.  Note that weak arrays cannot be marshaled using Per‐
34       vasives.output_value or the functions of the Marshal module.
35
36
37
38
39       val create : int -> 'a t
40
41
42       Weak.create  n returns a new weak array of length n .  All the pointers
43       are initially empty.   Raise  Invalid_argument  if  n  is  negative  or
44       greater than Sys.max_array_length -1 .
45
46
47
48
49       val length : 'a t -> int
50
51
52       Weak.length ar returns the length (number of elements) of ar .
53
54
55
56
57       val set : 'a t -> int -> 'a option -> unit
58
59
60       Weak.set ar n (Some el) sets the n th cell of ar to be a (full) pointer
61       to el ; Weak.set ar n None sets the n th cell of ar  to  empty.   Raise
62       Invalid_argument Weak.set if n is not in the range 0 to Weak.length a -
63       1 .
64
65
66
67
68       val get : 'a t -> int -> 'a option
69
70
71       Weak.get ar n returns None if the n th cell of  ar  is  empty,  Some  x
72       (where  x is the value) if it is full.  Raise Invalid_argument Weak.get
73       if n is not in the range 0 to Weak.length a - 1 .
74
75
76
77
78       val get_copy : 'a t -> int -> 'a option
79
80
81       Weak.get_copy ar n returns None if the n th cell of ar is empty, Some x
82       (where  x is a (shallow) copy of the value) if it is full.  In addition
83       to pitfalls with mutable values, the interesting difference with get is
84       that  get_copy  does  not  prevent  the incremental GC from erasing the
85       value in its current cycle ( get may delay the erasure to the  next  GC
86       cycle).   Raise Invalid_argument Weak.get if n is not in the range 0 to
87       Weak.length a - 1 .
88
89
90
91
92       val check : 'a t -> int -> bool
93
94
95       Weak.check ar n returns true if the n th cell of ar is full,  false  if
96       it is empty.  Note that even if Weak.check ar n returns true , a subse‐
97       quent Weak.get ar n can return None .
98
99
100
101
102       val fill : 'a t -> int -> int -> 'a option -> unit
103
104
105       Weak.fill ar ofs len el sets to el all pointers of ar from ofs to ofs +
106       len  - 1 .  Raise Invalid_argument Weak.fill if ofs and len do not des‐
107       ignate a valid subarray of a .
108
109
110
111
112       val blit : 'a t -> int -> 'a t -> int -> int -> unit
113
114
115       Weak.blit ar1 off1 ar2 off2 len  copies  len  weak  pointers  from  ar1
116       (starting  at  off1  )  to ar2 (starting at off2 ).  It works correctly
117       even if ar1 and ar2 are the same.  Raise Invalid_argument Weak.blit  if
118       off1  and len do not designate a valid subarray of ar1 , or if off2 and
119       len do not designate a valid subarray of ar2 .
120
121
122
123
124
125       === Weak hash tables ===
126
127
128
129       === A weak hash table is a hashed set of values. Each value  may  magi‐
130       cally  disappear  from  the  set when it is not used by the rest of the
131       program any more. This is normally used to share data structures  with‐
132       out inducing memory leaks.  Weak hash tables are defined on values from
133       a Hashtbl.HashedType module; the equal relation and hash  function  are
134       taken from that module. We will say that v is an instance of x if equal
135       x v is true.  The equal relation must be able to work on a shallow copy
136       of  the  values and give the same result as with the values themselves.
137       ===
138
139       module type S = sig end
140
141
142       The output signature of the functor Weak.Make .
143
144
145
146       module Make : functor (H : Hashtbl.HashedType) -> sig end
147
148
149       Functor building an implementation of the weak hash table structure.
150
151
152
153
154
155
156OCamldoc                          2007-05-24                           Weak(3)
Impressum