package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A manual memory manager for a set of mutable tuples. The point of Pool is to allocate a single long-lived block of memory (the pool) that lives in the OCaml major heap, and then to reuse the block, rather than continually allocating blocks on the minor heap.

A pool stores a bounded-size set of tuples, where client code is responsible for explicitly controlling when the pool allocates and frees tuples. One creates a pool of a certain capacity, which returns an empty pool that can hold that many tuples. One then uses new to allocate a tuple, which returns a Pointer.t to the tuple. One then uses get and set along with the pointer to get and set slots of the tuple. Finally, one free's a pointer to the pool's memory for a tuple, making the memory available for subsequent reuse.

In typical usage, one wraps up a pool with an abstract interface, giving nice names to the tuple slots, and only exposing mutation where desired.

All the usual problems with manual memory allocation are present with pools:

  • one can mistakenly use a pointer after it is freed
  • one can mistakenly free a pointer multiple times
  • one can forget to free a pointer

There is a debugging functor, Pool.Error_check, that is useful for building pools to help debug incorrect pointer usage.

module type S = Pool_intf.S

S is the module type for a pool.

module type Pool = Pool_intf.Pool
OCaml

Innovation. Community. Security.