.TH "NBD.Buffer" 3 2025-02-12 OCamldoc ""
.SH NAME
NBD.Buffer \- Persistent buffer used in AIO calls.
.SH Module
Module   NBD.Buffer
.SH Documentation
.sp
Module
.BI "Buffer"
 : 
.B sig end

.sp
Persistent buffer used in AIO calls\&.

.sp

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

.sp
A buffer that persists across calls, used in 
.ft B
NBD\&.aio_pread
.ft R
,
.ft B
NBD\&.aio_pwrite
.ft R
and similar\&.
.sp
In libnbd ≤ 1\&.18 this was a specially implemented type\&.
This was inefficient as zero copy was not possible\&.
.sp
In libnbd ≥ 1\&.20 this is just an alias for a 
.ft B
Bigarray
.ft R
,
so you can use functions from 
.ft B
Bigarray\&.Array1
.ft R
directly
if you prefer\&.  This also allows zero copy\&.
.sp
This type is compatible with the
.ft B
bigstring
.ft R
and
.ft B
bigstringaf
.ft R
libraries\&.

.sp

.I val alloc 
: 
.B int -> t
.sp
Allocate an uninitialized buffer\&.  The parameter is the size
in bytes\&.
.sp
In libnbd ≥ 1\&.20 this is an alias for 
.ft B
Bigarray\&.Array1\&.create
.ft R
\&.

.sp

.I val to_bytes 
: 
.B t -> bytes
.sp
Copy buffer to an OCaml 
.ft B
bytes
.ft R
object\&.
.sp
In libnbd ≥ 1\&.20 you can read from the bigarray directly to avoid
copying if you want\&.

.sp

.I val to_string 
: 
.B t -> string
.sp
Same as 
.ft B
NBD\&.Buffer\&.to_bytes
.ft R
but returns a 
.ft B
string
.ft R
instead\&.

.sp

.I val of_bytes 
: 
.B bytes -> t
.sp
Copy an OCaml 
.ft B
bytes
.ft R
object to a newly allocated buffer\&.
.sp
In libnbd ≥ 1\&.20 you can write to the bigarray directly to avoid
copying if you want\&.

.sp

.I val of_string 
: 
.B string -> t
.sp
Same as 
.ft B
NBD\&.Buffer\&.of_bytes
.ft R
but takes a 
.ft B
string
.ft R
instead\&.

.sp

.I val size 
: 
.B t -> int
.sp
Return the size of the buffer\&.
.sp
In libnbd ≥ 1\&.20 this is an alias for 
.ft B
Bigarray\&.Array1\&.dim
.ft R
\&.

.sp