bin_builder() creates a buffer that bytes are appended to with
bin_put() and taken out of with bin_take(). It grows by doubling (by
half once past 64 MiB), so a million appends cost a few dozen
reallocations, not a million copies; and it never grows past max.
Usage
bin_builder(reserve = 0, max = Inf)
bin_reserve(b, n)
bin_reset(b)
bin_take(b)
# S3 method for class 'zubin_builder'
as.raw(x)Value
bin_builder() returns a zubin_builder. bin_take() and
as.raw() return a raw vector; bin_size() returns a double;
bin_reserve() and bin_reset() return b, invisibly.
Details
A builder is an external pointer: it is not copied on modification, every
function below changes it in place, and it does not survive
saveRDS() or a restored session; using a restored builder is a
zubin_invalid_argument error. Its memory is freed when it is garbage
collected.
bin_take(b) returns the bytes and empties the builder, which keeps its
capacity and accepts new appends; as.raw(b) returns a copy and leaves the
builder as it is. bin_reserve(b, n) makes room for n more bytes now,
bin_reset(b) empties the builder without freeing its storage, and
bin_size(b) is the number of bytes it holds.
See also
bin_put() to append.