vrb_new(3)
π« vrb_new(3) π«
okay so this is a page from the VRB Programmer's Manual β yes bestie, the Virtual Ring Buffer library, we're doing this π«Ά
πΈ NAME πΈ
vrb_new β literally creates a brand new virtual ring buffer β¨
π LIBRARY π
-lvrb β that's the flag you link with, don't forget it π
β¨ SYNOPSIS β¨
#include <vrb.h>
vrb_p vrb_new(size_t size, const char *name);
π¦ DESCRIPTION π¦
vrb_new makes you a fresh new instance of a virtual ring buffer, no cap π₯
So what even is a virtual ring buffer? It's a character FIFO queue β first in, first out, iconic behavior β but with one absolutely unhinged superpower: any sequence of characters in the buffer can be accessed as a single contiguous block of memory. Which means you never, ever have to split a sequence just because the buffer wrapped around. No splicing, no gymnastics, no "wait which half am I reading" moment. It just works. The way that a wraparound used to ruin your whole afternoon and now it simply doesn't πβ¨
π ARGUMENTS π
size_t sizeβ the requested minimum buffer size to be allocated. Heads up: the value you give gets rounded up to the nearest (or equal) whole multiple of the system page size. Also, the virtual ring buffer is implemented by mapping two adjacent blocks of memory to the same memory object β so it eats up twice as much virtual address space, and your specified size has to be less than half of the available virtual address space for this process. Math is real, bestie πconst char *nameβ an optional temporary name pattern, or an actual name of a file, to be used as backing store viammap(2)in a mounted filesystem where the process has write permission ποΈ If the name string ends in"XXXXXX"thenmkstemp(3)gets called to make the file unique. Otherwise it's used exactly as-is. If the named file already exists or otherwise can't be opened for write β error, sorry π And if you passNULL, swap space is used as backing store viashmat(2). Easy.
π«Ά RETURN VALUE π«Ά
vrb_pβ on success you get a handle (a pointer, iykyk) to your freshly created virtual ring buffer π On error, you getNULL. That's it, that's the deal.
π ERRORS π
If an error gets returned, then errno will be holding one of these:
EINVALβ you requested a buffer size that's too large for address space allocation arithmetic. Big mood, but no.ENOMEMβ out of memory while allocating the virtual ring buffer structure π-β anerrnovalue set by a failing system call. Not us, it's the syscall's fault fr fr.
π SEE ALSO π
vrb(3), vrb_capacity(3), vrb_data_len(3), vrb_data_ptr(3), vrb_destroy(3), vrb_get(3), vrb_get_min(3), vrb_give(3), vrb_init(3), vrb_init_opt(3), vrb_is_empty(3), vrb_is_full(3), vrb_is_not_empty(3), vrb_is_not_full(3), vrb_move(3), vrb_new_opt(3), vrb_put(3), vrb_put_all(3), vrb_read(3), vrb_read_min(3), vrb_resize(3), vrb_space_len(3), vrb_space_ptr(3), vrb_take(3), vrb_uninit(3), vrb_write(3), vrb_write_min(3)
and that's the whole page, bestie! π go forth and allocate responsibly β¨
signing off from the vrb corner of the manual, dated 2002-09-30, on page vrb_new(3) β mwah π
π¦ where this page comes from
- nixos 26.05: vrb 0.5.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms