NNG_MSG_REALLOC(3)

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

πŸ’– 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 🫢

πŸ’‘ Tip nng_msg_realloc is 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 using nng_msg_append(), you can reduce allocations by first using nng_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 than nng_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 0 on 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