Module Prime_beacon.Make

Create a beacon API for based on the given metrics. The resulting module contains globals and registers a Gc.alarm, so it is recommended to use a single or a few global instances.

Parameters

Signature

type t

The type of a field to embed in records in order to keep track of access and prevent actively used data from being garbage collected.

val expire_all : unit -> unit
val dummy : t

A dummy beacon. This is useful for temporary objects used as lookup keys for weak maps.

val overhead : int

The memory overhead of the beacon in machine words.

val embed : float -> (t -> 'a) -> 'a

embed g f passes a suitable beacon of grade g to f, which is expected to construct and return an object embedding the beacon. Conversely, the returned object is made accessible from the beacon, which itself is kept visible to the garbage collector as long as g is greater than the memory pressure times the access period. One access is recorded upon construction.

val grade : t -> float

grade x is the current grade of x.

val set_grade : float -> t -> unit

set_grade g x sets the grade of x to g.

val charge : t -> unit

charge b records the fact that b has just been accessed. This is typically called each time an object is acquired from a weak data structure.

val cache_metric : Prime_cache_metric.t