BIN(3)
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 theBinpointed to bybp. Every item in a bin can be freed with one single call tobinfree; 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.binallocreturn tea β returns a pointer to a new block of at leastsizebytes. The block is suitably aligned for storage of any type of object. No two active pointers frombinallocwill have the same value. The callbinalloc(0)returns a valid pointer rather than null. Ifclris non-zero, the allocated memory is set to0; otherwise, the contents are undefined. π«Άbingrowβ extends the size of a block of memory returned bybinalloc.bpmust point to the same bin group used to allocate the original block, andosizemust be the last size used to allocate or grow the block. A pointer to a block of at leastsizebytes is returned, with the same contents in the firstosizelocations. Ifclris non-zero, the remaining bytes are set to0, and are undefined otherwise. Ifopis nil, it andosizeare ignored, and the result is the same as callingbinalloc. β¨binfreeβ frees every item in the bin with one call. The chunks below are free'd upon a call tobinfree.- chunk tea β
binallocandbingrowallocate large chunks of memory usingmalloc(3)and return pieces of these chunks. The chunks are free'd upon a call tobinfree. π
π 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! π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms