iarray_allocate(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– iarray_allocate β€” get pointer to nth element in iarray πŸ’–

okay bestie, welcome to the Library Functions Manual, page iarray_allocate(3). this one's short and sweet but it's so useful, i promise. let's go 🫢


✨ SYNTAX ✨

the sacred summoning ritual, literally copy-paste this:

#include <libowfat/iarray.h>

void* iarray_allocate(iarray* x, size_t pos);

and here's how the girlies actually call it in the wild:

iarray x;
size_t pos;
t* p = iarray_allocate(&x,pos);

🌸 DESCRIPTION 🌸

okay so iarray_allocate is basically iarray_get's glow-up era. they're cousins, fr fr. the difference? if the element you're asking for is not in the array, this function will resize the array for you. no cap. it just handles it. main character energy πŸ’…

but β€” and listen, this matters β€” if the resize fails, iarray_allocate returns NULL and leaves the array untouched. it does not half-do the thing and leave you with a cursed broken array. it's polite like that. πŸŽ€

it's also safe to use in environments with multiple threads, bestie. thread-safe queen. but there's a catch: it can block for an indeterminate time if other threads are reallocating the array at the same time. so like, she's safe, she's just not always fast. she might be waiting in the group chat for someone else to finish typing. 😭

note: it is safe to use iarray_allocate anywhere you'd otherwise use iarray_get. the only reason to reach for iarray_get instead is optimization. that's it. that's the whole reason. iykyk.

πŸ‘‘ RETURN VALUE πŸ‘‘

  • returns a pointer to the requested element ✨ iconic, we love
  • if there was a memory allocation failure, it returns NULL πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

go read these too, they're the rest of the friend group:


and that's the whole page, bestie!! 🌈 source of truth is the Library Functions Manual, page iarray_allocate(3), and it's the footer of the original too so like, that's the vibe check passed. go forth and allocate responsibly πŸ’œβœ¨πŸŒΈ