BSON_ARRAY_ALLOC0(3)

πŸ“¦
version 2.5.6 Β· 3 versions
, in epel 10

πŸ’… 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 β€” a size_t holding the number of objects you wanna allocate. like, how many of the thing. πŸ“
  • elem_size β€” a size_t holding the size of each object, in bytes. that's the sizeof energy, 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:

if num_elems * elem_size cannot be represented in a size_t, OR if there was a failure to allocate num_elems * elem_size bytes, the process will be aborted. 😭 like, full on aborted. not a gentle NULL return, 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. 🫢


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