man-pages/man3/Stdlib.Ephemeron.3o.html
2021-03-31 01:06:50 +01:00

180 lines
3.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Stdlib.Ephemeron</TITLE>
</HEAD><BODY>
<H1>Stdlib.Ephemeron</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Stdlib.Ephemeron - no description
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Stdlib.Ephemeron
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Ephemeron</B>
<BR>&nbsp;:&nbsp;
<B>(module Stdlib__ephemeron)</B>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
Ephemerons and weak hash table are useful when one wants to cache
or memorize the computation of a function, as long as the
arguments and the function are used, without creating memory leaks
by continuously keeping old computation results that are not
useful anymore because one argument or the function is freed. An
implementation using
<B>Hashtbl.t</B>
is not suitable because all
associations would keep in memory the arguments and the result.
<P>
Ephemerons can also be used for &quot;adding&quot; a field to an arbitrary
boxed ocaml value: you can attach an information to a value
created by an external library without memory leaks.
<P>
Ephemerons hold some keys and one or no data. They are all boxed
ocaml values. The keys of an ephemeron have the same behavior
than weak pointers according to the garbage collector. In fact
ocaml weak pointers are implemented as ephemerons without data.
<P>
The keys and data of an ephemeron are said to be full if they
point to a value, empty if the value have never been set, have
been unset, or was erased by the GC. In the function that accesses
the keys or data these two states are represented by the
<B>option</B>
type.
<P>
The data is considered by the garbage collector alive if all the
full keys are alive and if the ephemeron is alive. When one of the
keys is not considered alive anymore by the GC, the data is
emptied from the ephemeron. The data could be alive for another
reason and in that case the GC will not free it, but the ephemeron
will not hold the data anymore.
<P>
The ephemerons complicate the notion of liveness of values, because
it is not anymore an equivalence with the reachability from root
value by usual pointers (not weak and not ephemerons). With ephemerons
the notion of liveness is constructed by the least fixpoint of:
A value is alive if:
<P>
-it is a root value
<P>
-it is reachable from alive value by usual pointers
<P>
-it is the data of an alive ephemeron with all its full keys alive
<P>
Notes:
<P>
-All the types defined in this module cannot be marshaled
using
<B>output_value</B>
or the functions of the
<B>Marshal</B>
module.
<P>
Ephemerons are defined in a language agnostic way in this paper:
B. Hayes, Ephemerons: a New Finalization Mechanism, OOPSLA'9
<P>
<I>module type S = </I>
<B>sig end</B>
<P>
<P>
The output signature of the functor
<B>Ephemeron.K1.Make</B>
and
<B>Ephemeron.K2.Make</B>
.
These hash tables are weak in the keys. If all the keys of a binding are
alive the binding is kept, but if one of the keys of the binding
is dead then the binding is removed.
<P>
<P>
<I>module type SeededS = </I>
<B>sig end</B>
<P>
<P>
The output signature of the functor
<B>Ephemeron.K1.MakeSeeded</B>
and
<B>Ephemeron.K2.MakeSeeded</B>
.
<P>
<P>
<I>module K1 : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<I>module K2 : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<I>module Kn : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<I>module GenHashTable : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:57 GMT, March 31, 2021
</BODY>
</HTML>