NN_ALLOCMSG(3)
π 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
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms