1Stdlib.Ephemeron(3)              OCaml library             Stdlib.Ephemeron(3)
2
3
4

NAME

6       Stdlib.Ephemeron - no description
7

Module

9       Module   Stdlib.Ephemeron
10

Documentation

12       Module Ephemeron
13        : (module Stdlib__ephemeron)
14
15
16
17
18
19
20
21
22
23       Ephemerons  and  weak hash tables are useful when one wants to cache or
24       memorize the computation of a function, as long as  the  arguments  and
25       the  function  are  used, without creating memory leaks by continuously
26       keeping old computation results that are not useful anymore because one
27       argument or the function is freed. An implementation using Hashtbl.t is
28       not suitable because all associations would keep the arguments and  the
29       result in memory.
30
31       Ephemerons  can also be used for "adding" a field to an arbitrary boxed
32       OCaml value: you can attach some information to a value created  by  an
33       external library without memory leaks.
34
35       Ephemerons  hold some keys and one or no data. They are all boxed OCaml
36       values. The keys of an ephemeron have the same behavior as weak  point‐
37       ers according to the garbage collector. In fact OCaml weak pointers are
38       implemented as ephemerons without data.
39
40       The keys and data of an ephemeron are said to be full if they point  to
41       a  value,  or empty if the value has never been set, has been unset, or
42       was erased by the GC. In the function that accesses the  keys  or  data
43       these two states are represented by the option type.
44
45       The  data  is considered by the garbage collector alive if all the full
46       keys are alive and if the ephemeron is alive. When one of the  keys  is
47       not  considered  alive  anymore by the GC, the data is emptied from the
48       ephemeron. The data could be alive for another reason and in that  case
49       the  GC will not free it, but the ephemeron will not hold the data any‐
50       more.
51
52       The ephemerons complicate the notion of liveness of values, because  it
53       is  not anymore an equivalence with the reachability from root value by
54       usual pointers (not weak  and  not  ephemerons).  With  ephemerons  the
55       notion  of liveness is constructed by the least fixpoint of: A value is
56       alive if:
57
58       -it is a root value
59
60       -it is reachable from alive value by usual pointers
61
62       -it is the data of an alive ephemeron with all its full keys alive
63
64       Notes:
65
66       -All the types defined in this module cannot be  marshaled  using  out‐
67       put_value or the functions of the Marshal module.
68
69       Ephemerons  are  defined  in  a language agnostic way in this paper: B.
70       Hayes, Ephemerons: A New Finalization Mechanism, OOPSLA'97
71
72       module type S = sig end
73
74
75       The   output   signature   of   the   functor   Ephemeron.K1.Make   and
76       Ephemeron.K2.Make .  These hash tables are weak in the keys. If all the
77       keys of a binding are alive the binding is kept, but if one of the keys
78       of the binding is dead then the binding is removed.
79
80
81       module type SeededS = sig end
82
83
84       The   output  signature  of  the  functor  Ephemeron.K1.MakeSeeded  and
85       Ephemeron.K2.MakeSeeded .
86
87
88       module K1 : sig end
89
90
91
92
93       module K2 : sig end
94
95
96
97
98       module Kn : sig end
99
100
101
102
103       module GenHashTable : sig end
104
105
106
107
108
109
110
111OCamldoc                          2020-09-01               Stdlib.Ephemeron(3)
Impressum