NNG_ALLOC(3)
β¨ 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
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms