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

NAME

6       Ephemeron - Ephemerons and weak hash table
7

Module

9       Module   Ephemeron
10

Documentation

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