package core
Install
Dune Dependency
Authors
Maintainers
Sources
md5=743a141234e04210e295980f7a78a6d9
sha512=61b415f4fb12c78d30649fff1aabe3a475eea926ce6edb7774031f4dc7f37ea51f5d9337ead6ec73cd93da5fd1ed0f2738c210c71ebc8fe9d7f6135a06bd176f
doc/core.heap_block/Heap_block/index.html
Module Heap_block
Source
A heap block is a value that is guaranteed to live on the OCaml heap, and is hence guaranteed to be usable with finalization or in a weak pointer.
It is an abstract type so we can use the type system to guarantee that the values we put in weak pointers and use with finalizers are heap blocks.
Some examples of values that are not heap-allocated are integers, constant constructors, booleans, the empty array, the empty list, the unit value. The exact list of what is heap-allocated or not is implementation-dependent. Some constant values can be heap-allocated but never deallocated during the lifetime of the program, for example a list of integer constants; this is also implementation-dependent. You should also be aware that compiler optimizations may duplicate some immutable values, for example floating-point numbers when stored into arrays; thus they can be finalized and collected while another copy is still in use by the program.
The results of calling String.make
, Bytes.create
, Bytes.make
, Array.make
, and Pervasives.ref
are guaranteed to be heap-allocated and non-constant except when the length argument is 0
.
create v
returns Some t
if v
is a heap block, where t
is physically equal to v
.