BIN(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

Okay bestie, welcome to BIN(3) β€” the page from the Library Functions Manual that explains grouped memory allocation. It's giving "one bin, many little allocations, one big cleanup moment" energy. πŸ’–

✨ NAME ✨

binalloc, bingrow, binfree β€” grouped memory allocation. That's the whole vibe: allocate into a bin, grow stuff inside the bin, then free the entire bin in one go.

πŸŽ€ SYNOPSIS πŸŽ€

Here's the exact C invite list, bestie β€” keep it cute and keep it verbatim:

#include <u.h>
#include <libc.h>
#include <bin.h>

typedef struct BinBin;

void  *binalloc(Bin **bp, ulong size, int clr);

void  *bingrow(Bin **bp, void *op, ulong osize,
          ulong size, int clr);

void  binfree(Bin **bp);

πŸ’– DESCRIPTION πŸ’–

These routines are your grouped memory allocation and deallocation besties. Simple, no drama.

  • binalloc β€” allocates an item and adds it to the Bin pointed to by bp. Every item in a bin can be freed with one single call to binfree; there is literally no way to free a single item on its own. It's all-for-one, one-for-all, group-chat cleanup energy.
  • binalloc return tea β€” returns a pointer to a new block of at least size bytes. The block is suitably aligned for storage of any type of object. No two active pointers from binalloc will have the same value. The call binalloc(0) returns a valid pointer rather than null. If clr is non-zero, the allocated memory is set to 0; otherwise, the contents are undefined. 🫢
  • bingrow β€” extends the size of a block of memory returned by binalloc. bp must point to the same bin group used to allocate the original block, and osize must be the last size used to allocate or grow the block. A pointer to a block of at least size bytes is returned, with the same contents in the first osize locations. If clr is non-zero, the remaining bytes are set to 0, and are undefined otherwise. If op is nil, it and osize are ignored, and the result is the same as calling binalloc. ✨
  • binfree β€” frees every item in the bin with one call. The chunks below are free'd upon a call to binfree.
  • chunk tea β€” binalloc and bingrow allocate large chunks of memory using malloc(3) and return pieces of these chunks. The chunks are free'd upon a call to binfree. πŸŽ€

πŸ“ SOURCE πŸ“

/src/libbin β€” that's the source home, bestie.

πŸ‘€ SEE ALSO πŸ‘€

malloc(3) β€” go say hi.

🚨 DIAGNOSTICS 🚨

binalloc and bingrow return 0 if there is no available memory. That's the official "bestie, the memory budget said no" signal. πŸ’€

Bye bestie πŸ’– β€” footer tea: this is the BIN(3) page from the Library Functions Manual, source/version stamp BIN(3), and no separate date was printed. Catch you in the next manual! 🌈