array(3)
π array(3) β the array library interface π
okay bestie, welcome to the array(3) page, straight outta the Library Functions Manual β¨ this is the whole array library interface and honestly? it's giving organized. it's giving memory-safe girlboss. let's go π«Ά
πΈ NAME πΈ
array β The array library interface π
β¨ SYNTAX β¨
#include <libowfat/array.h>
like literally just include it and you're in, no cap π
π¦ DESCRIPTION π¦
so an allocated array variable is keeping track of three things at all times, and she's tracking them obsessively:
- a (nonzero) pointer to a dynamically allocated region of memory πΎ
- the number of bytes allocated (always positive, periodt) π
- and the number of bytes initialized (which lives somewhere between
0and the number of bytes allocated) β
there are two other possibilities for the state of an array variable, and they're the sad ones: unallocated and failed π in both of those cases there is no dynamically allocated region of memory. none. zero. the void.
a new array variable is normally created as a static variable, like so:
#include <libowfat/array.h>
static array x;
at this point it's unallocated β just a baby, no memory yet π the array library provides various allocation and inspection functions to fix that.
a new array variable can also be created dynamically π but listen, this is important: it must be initialized to all-0, meaning unallocated, before it is given to any of the array functions. and it must be returned to the unallocated (or failed) state β for example with array_reset β before it is destroyed. these rules prevent all memory leaks π§ and memory leaks are not the vibe.
π Expansion and inspection π
array x;
t* p1 = array_allocate(&x,sizeof(t),pos);
t* p2 = array_get(&x,sizeof(t),pos);
t* p3 = array_start(&x);
int64 len = array_length(&x,sizeof(t));
int64 bytes = array_bytes(&x);
βοΈ Truncation and deallocation βοΈ
array x;
array_truncate(&x,sizeof(t),len);
array_trunc(&x);
array_reset(&x);
array_fail(&x);
βοΈ Comparison βοΈ
array x;
array y;
if (array_equal(&x,&y))
/* arrays are equal... */
π§© Concatenation π§©
array x;
array y;
array_cat(&x,&y);
array_catb(&x,"fnord",5);
array_cats(&x,"fnord");
array_cats0(&x,"fnord"); /* also append the \0 */
array_cat0(&x); /* append \0 */
array_cate(&x,"fnord",1,4); /* append "nor" */
π ORIGINAL API DEFINITION π
http://cr.yp.to/lib/array.html
π SEE ALSO π
array_get(3), array_start(3), array_fail(3)
and that's the whole page bestie π this was array(3) from the Library Functions Manual β go forth and allocate responsibly, return everything to unallocated before it's destroyed, and remember: no leaks, only slay π
β¨ππ¦
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms