NN_ALLOCMSG(3)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’– NN_ALLOCMSG(3) β€” bestie edition πŸ’–

okay so this is nn_allocmsg, from the nanomsg 1.2.2 manual, section 3 (library calls, iykyk). it's a whole vibe and also a whole function. let's get into it 🫢


✨ NAME ✨

nn_allocmsg β€” allocate a message. that's it. that's the whole job. she allocates. she slays. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <nanomsg/nn.h>

void *nn_allocmsg (size_t size, int type);

πŸ¦‹ DESCRIPTION πŸ¦‹

so bestie, what she does is allocate a message of the specified size, and the whole point is that you're gonna send it in zero-copy fashion. no cap. ✨

after allocation the content of the message is undefined, so like… don't peek at it, it's giving mystery. it's your job to fill it in. that's the deal. πŸ™ˆ

now, nn_send(3) and nn_sendmsg(3) are totally fine with sending arbitrary buffers, they're not picky, they're chill. BUT β€” buffers allocated with nn_allocmsg() can be more efficient for large messages, because they let you use those zero-copy techniques. so if your message is big big, this is the move. πŸ’…

the type parameter specifies the type of allocation mechanism to use. Zero is the default one. but listen β€” individual transport mechanisms may define their own allocation mechanisms, like allocating in shared memory, or allocating a memory block pinned down to a physical memory address. and when you use one of those special allocations with the transport that defines it, it should be more efficient than the default allocation mechanism. iconic behavior honestly. πŸ”₯


πŸ’œ RETURN VALUE πŸ’œ

if the function succeeds, you get a pointer to the newly allocated buffer back. yay! πŸŽ€

otherwise, NULL is returned and errno is set to one of the values defined below. (yes, it says "set to to" in the original and honestly? relatable typo energy, keeping the facts intact tho.)


πŸ“ ERRORS πŸ“

  • EINVAL β€” the supplied allocation type is invalid. like, that type is not it. πŸ’€
  • ENOMEM β€” not enough memory to allocate the message. the machine said no. 😭

⭐ EXAMPLE ⭐

void *buf = nn_allocmsg (12, 0);
memcpy (buf, "Hello world!", 12);
nn_send (s, &buf, NN_MSG, 0);

look at her go. allocate twelve bytes, copy "Hello world!" in there (that's 12 characters bestie, count them), and send it with NN_MSG. chef's kiss. πŸ‘‘


🌈 SEE ALSO 🌈

go read those too, they're all part of the same friend group. 🫢


πŸ‘‘ AUTHORS πŸ‘‘

Martin Sustrik <sustrik@250bpm.com> β€” thank you for your service, king. πŸ’œ


and that's the whole page, bestie!! this version of NN_ALLOCMSG(3) came from the nanomsg 1.2.2 release, dated 2026-01-16, and yes she is still serving library-call realness to this very day. go forth and allocate responsibly. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from