BSON_ARRAY_ALLOC0(3)
π
BSON_ARRAY_ALLOC0(3) β the libbson glow-up of calloc() π
okay so bestie, welcome to libbson's very own BSON_ARRAY_ALLOC0 manual page β yes that's the 3 section, we're in library-call territory now, iykyk β¨
β¨ SYNOPSIS β¨
like, here's the whole vibe in code, copy it exactly bestie:
#define BSON_ARRAY_ALLOC0(Count, Type) \
(Type*) bson_array_alloc0 (Count, sizeof (Type))
void *
bson_array_alloc0 (size_t num_elems, size_t elem_size);
so there's a macro and a function, and the macro is literally just the function but it does the sizeof for you so you don't have to π iconic behaviour honestly.
π¦ PARAMETERS π¦
num_elemsβ asize_tholding the number of objects you wanna allocate. like, how many of the thing. πelem_sizeβ asize_tholding the size of each object, in bytes. that's thesizeofenergy, the "how chunky is one of these" energy.
πΈ DESCRIPTION πΈ
okay so listen. this is a portable calloc() wrapper β it allocates an array of objects AND it sets that memory to zero. the way that it zeroes everything out?? obsessed. no leftover garbage bytes, no "why is my struct full of mystery values" moments. we love a clean slate π
but now the serious part, bestie, pay attention:
ifnum_elems * elem_sizecannot be represented in asize_t, OR if there was a failure to allocatenum_elems * elem_sizebytes, the process will be aborted. π like, full on aborted. not a gentleNULLreturn, not a "try again later". the whole thing goes down.
π WARNING
This function will abort on failure to allocate memory. fr fr. do not expect a NULL back and go on with your life β that is not the vibe here. π
β RETURNS β
a pointer to a memory region which HAS been zeroed. capital H-A-S. it's already zeroed. you don't gotta memset, bestie, it's handled π
π AUTHOR π
MongoDB, Inc β periodt. π«Ά
π COPYRIGHT π
2009-present, MongoDB, Inc. β that's the whole copyright line, keep it sacred π
and that's the page!! mwah π this was libbson 2.5.6, dated Oct 09, 2026 β go forth and allocate responsibly, bestie, and remember: zeroed memory is self-care π§ββοΈβ¨π
π¦ where this page comes from
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms