NBD.Buffer(3)

NAME
NBD.Buffer - Persistent buffer used in AIO calls.

Module
Module NBD.Buffer

Documentation

Module Buffer
 : sig end

Persistent buffer used in AIO calls.

type t = (char, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t

A buffer that persists across calls, used in NBD.aio_pread , NBD.aio_pwrite and similar.

In libnbd ≤ 1.18 this was a specially implemented type. This was inefficient as zero copy was not possible.

In libnbd ≥ 1.20 this is just an alias for a Bigarray , so you can use functions from Bigarray.Array1 directly if you prefer. This also allows zero copy.

This type is compatible with the bigstring and bigstringaf libraries.

val alloc : int -> t

Allocate an uninitialized buffer. The parameter is the size in bytes.

In libnbd ≥ 1.20 this is an alias for Bigarray.Array1.create .

val to_bytes : t -> bytes

Copy buffer to an OCaml bytes object.

In libnbd ≥ 1.20 you can read from the bigarray directly to avoid copying if you want.

val to_string : t -> string

Same as NBD.Buffer.to_bytes but returns a string instead.

val of_bytes : bytes -> t

Copy an OCaml bytes object to a newly allocated buffer.

In libnbd ≥ 1.20 you can write to the bigarray directly to avoid copying if you want.

val of_string : string -> t

Same as NBD.Buffer.of_bytes but takes a string instead.

val size : t -> int

Return the size of the buffer.

In libnbd ≥ 1.20 this is an alias for Bigarray.Array1.dim .

val is_zero : ?sub:int * int -> t -> bool

Return true if and only if the buffer contains only zero bytes.

The optional ?sub = (offset, len) can be used to check part of a buffer.