package ocaml_intrinsics

  1. Overview
  2. Docs

Native_pointer uses Nativeint to hold a pointer to a memory block allocated outside the OCaml heap. The pointer is not required to be aligned.

type t = private nativeint
val create : nativeint -> t
val ext_pointer_as_native_pointer : int -> t

ext_pointer_as_native_pointer p takes an int p that encodes a pointer to a memory block outside of the OCaml heap, decodes p by clearing the least significant bit of p, and boxes the result as nativeint. Unlike untagging, decoding p does not shift the bits of p.

module Immediate (V : sig ... end) : sig ... end
module Int : sig ... end
module Bool : sig ... end
val load_untagged_int : t -> int

load_untagged_int t reads untagged int pointed to by t and returns the corresponding tagged int. This should only be used to read a value written by store_untagged_int. Otherwise, if the value has most significant bit set, it will be lost by tagging. To avoid it, use load_unboxed_nativeint and check before converting to int (should not allocate). Their native code C stub is the same.

val store_untagged_int : t -> int -> unit

store_untagged_int t d untags d and stores the result to the memory pointed to by t.

val load_unboxed_nativeint : t -> nativeint

load_unboxed_nativeint t reads unboxed nativeint pointed to by t and returns the corresponding (boxed) nativeint allocated on the OCaml heap.

val store_unboxed_nativeint : t -> nativeint -> unit

store_unboxed_nativeint t d stores the unboxed nativeint to the memory pointed to by t.

val load_unboxed_int64 : t -> int64

load_unboxed_int64 t reads unboxed int64 pointed to by t and returns the corresponding (boxed) int64 allocated on the OCaml heap.

val store_unboxed_int64 : t -> int64 -> unit

store_unboxed_int64 t d stores the unboxed int64 to the memory pointed to by t.

val load_unboxed_int32 : t -> int32

load_unboxed_int32 t reads unboxed int32 pointed to by t and returns the corresponding (boxed) int32 allocated on the OCaml heap.

val store_unboxed_int32 : t -> int32 -> unit

store_unboxed_int32 t d stores the unboxed int32 to the memory pointed to by t.

For float operations, the pointer must be aligned at least to the native integer machine width (meaning on 32-bit platforms, a 32-bit-aligned pointer is acceptable even though the width of the float is 64 bits).

val load_unboxed_float : t -> float

load_unboxed_float t reads the unboxed float pointed to by t. (If the result is not directly passed to another operation expecting an unboxed float, then it will be boxed.)

val store_unboxed_float : t -> float -> unit

store_unboxed_float t d stores the unboxed float to the memory pointed to by t.