BSON_STRING_NEW(3)

πŸ’– BSON_STRING_NEW πŸ’–

okay bestie, so this one is a libbson page, and it's the ✨ string builder ✨ origin story. fair warning though, she's a legacy queen now β€” deprecated since version 1.29.0 β€” so appreciate her for the lore but don't build your whole personality on her, mwah πŸ’…


🌸 SYNOPSIS 🌸

bson_string_t *
bson_string_new (const char *str);

like... that's it. that's the whole vibe. one function, one arg, one little pointer of destiny 🫢


πŸŽ€ PARAMETERS πŸŽ€

  • str β€” a string you want copied, or NULL. literally your choice, she supports both, no judgement πŸ’–

✨ DESCRIPTION ✨

So what she does is create a brand-new string builder, and the way she grows is power-of-two growth of buffers β€” like, she doubles up when she needs more room, which is honestly so main character of her πŸ¦‹

Once you've got her, you use the various bson_string_append*() functions to append stuff onto the string. that's the whole workflow, no cap.

BIG WARNING, LOCK IN: the length of the resulting string β€” and yes, that includes the NULL terminator, bestie, don't forget her β€” MUST NOT exceed UINT32_MAX. that's not a suggestion, that's a hard limit. exceed it and things get real bad real fast 😭

🫢 RETURNS 🫢

She hands you back a newly allocated bson_string_t β€” and here's the part people always forget β€” you gotta free her with bson_string_free() when you're done with her. no ghosting your allocations, that's not the energy we're bringing into this repo πŸ’€


πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” the icons themselves, periodt.


2009-present, MongoDB, Inc.


and that's the page!! πŸŽ€ this was libbson version 1.30.13, dated Oct 09, 2026 β€” go free your strings and hydrate, ily bye πŸ’œβœ¨

πŸ“¦ where this page comes from