NNG_MSG_REALLOC(3)
π nng_msg_realloc β reallocate a message π
okay bestie so this one lives in the NNG Reference Manual and it's genuinely one of the most useful little gremlins in the whole message API. sit down, hydrate, let's get into it β¨
β¨ NAME β¨
nng_msg_realloc β girl, we're reallocating a message π
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
int nng_msg_realloc(nng_msg *msg, size_t size);
π¦ DESCRIPTION π¦
so. nng_msg_realloc() re-allocates a message so that it has a body of length size. that's it, that's the job.
and here's the cute part β this function tries to avoid extra allocations, and it will reuse the existing memory when possible. frugal queen. she's not out here allocating for no reason π«Ά
π‘ Tipnng_msg_reallocis the move when you wanna create space for direct writing of data. like, just write straight into it, no middleman. BUT β if you're out here appending many small pieces of data to a message usingnng_msg_append(), you can reduce allocations by first usingnng_msg_reserve()to create sufficient space. no cap. plan ahead, save your future self the drama. in any case, reallocating or appending to a message is guaranteed to succeed if the resulting body length is less thannng_msg_capacity(). periodt.
β οΈ Note pointers to message body and header content obtained prior to this function must not be in use. like, at all. because the underlying memory used for the message may have changed β particularly if the message size is increasing. so if you're holding a pointer from before, that thing might be pointing at vibes and dust now. π
β RETURN VALUES β
- returns
0on success π - returns non-zero otherwise π
π ERRORS π
NNG_ENOMEMβ insufficient free memory exists to reallocate a message. your system said "bestie I literally cannot", and honestly, fair. π
π SEE ALSO π
nng_msg_reserve(3), nng_msg_alloc(3), nng_msg_append(3), nng_msg_body(3), nng_msg_chop(3), nng_msg_free(3), nng_msg_insert(3), nng_msg_len(3), nng_msg_trim(3), nng_strerror(3), nng_msg(5), nng(7)
and that's the whole page, bestie!! this edition dropped in the version dated 2026-06-30, under the NNG_MSG_REALLOC(3) title, and it's part of the NNG reference manual collection. go reallocate something responsibly and slay your day πβ¨π§
π¦ 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