NNG_ALLOC(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

✨ NNG_ALLOC(3) ✨

okay bestie, buckle up, because today we're talking about nng_alloc from the NNG Reference Manual β€” it's giving "I just need some memory" and honestly? same. 🫢


🌸 NAME 🌸

nng_alloc β€” allocate memory, bestie. that's it, that's the whole job. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <nng/nng.h>

void *nng_alloc(size_t size);

look at that. clean. iconic. no notes. ✨


πŸŽ€ DESCRIPTION πŸŽ€

so the way that nng_alloc() works is it grabs you a contiguous memory region of at least size bytes. at least, babes β€” maybe more, don't be weird about it. and here's the slay: that memory will be 64-bit aligned. πŸ”₯

the memory it hands back can be used to hold message buffers, and if that's what you're doing with it, you can pass it directly to nng_send() using the flag NNG_FLAG_ALLOC. literally so convenient. 😭 alternatively, when you don't need it anymore, you can free it with nng_free(). periodt.

⚠️ Important ⚠️ β€” do NOT use the system free() function to release this memory. on some platforms it might seem to work, but it is not guaranteed and it may lead to a crash or other undesirable and unpredictable behavior. this is not a drill, bestie, do not do it. πŸ’€πŸ™ˆ

πŸ‘‘ RETURN VALUES πŸ‘‘

this function returns a pointer to the allocated memory on success, and NULL otherwise. that's the vibe check right there.


🌈 ERRORS 🌈

so, no errors are returned, but a NULL return value should be treated the same as NNG_ENOMEM. fr fr, if you get NULL, act accordingly. πŸ’œ


🧚 SEE ALSO 🧚


and that's the whole page, bestie!! πŸŽ€ stay aligned (64-bit-ly), always free with nng_free() and never with the system free(), and you'll be main character energy forever. πŸ’…βœ¨

this has been your girl, reporting from the NNG Reference Manual, dated 2026-06-30. mwah. πŸ’–πŸ¦‹πŸŒΈ
πŸ“¦ where this page comes from