NBD.Buffer(3)

✨ NAME ✨

NBD.Buffer β€” persistent buffer used in AIO calls, bestie. This is the NBD.Buffer(3) page and she is lowkey iconic. πŸ’…

πŸŽ€ Module πŸŽ€

Module NBD.Buffer

πŸ’– Documentation πŸ’–

🧚 Module Buffer

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. No cap.

In libnbd ≀ 1.18 this was a specially implemented type. That was inefficient because 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. Slay. πŸ”₯

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.


Okay bye bestie! This cutie was brought to you by OCamldoc, dated 2026-10-13, and it’s the NBD.Buffer(3) manual page. Mwah! πŸ’‹βœ¨

πŸ“¦ where this page comes from