ZMQ_MSG_INIT_DATA(3)
π ZMQ_MSG_INIT_DATA(3) π
okay bestie, gather round, because we're talking about zmq_msg_init_data from the 0MQ manual and it is lowkey one of the most main-character functions in the whole zmq_msg family. no cap. π«Ά
β¨ NAME β¨
zmq_msg_init_data β initialise a 0MQ message from a supplied buffer π
πΈ SYNOPSIS πΈ
typedef void (zmq_free_fn) (void *data, void *hint);
int zmq_msg_init_data (zmq_msg_t *msg, void *data, size_t size,
zmq_free_fn *ffn, void *hint);
π¦ DESCRIPTION π¦
so the way that zmq_msg_init_data() works is: it shall initialise the message object referenced by msg so it represents the content referenced by the buffer sitting at address data, which is size bytes long. π
and here's the iconic part β no copy of data shall be performed and 0MQ shall take ownership of the supplied buffer. like, it's yours until it's theirs. no dupe, no backup, just vibes and ownership transfer. π
if provided, the deallocation function ffn shall be called once the data buffer is no longer required by 0MQ, with the data and hint arguments supplied to zmq_msg_init_data(). so you hand it the cleanup function and it calls it later with the exact same args. mutual trust. π€
β οΈ Caution β Never accesszmq_msg_tmembers directly, instead always use thezmq_msgfamily of functions. do NOT peek behind the curtain, bestie, that's not the vibe. π
β οΈ Caution β The deallocation function ffn needs to be thread-safe, since it will be called from an arbitrary thread. it's giving "any thread, any time, no warning" energy. be ready. π
β οΈ Caution β If the deallocation function is not provided, the allocated memory will not be freed, and this may cause a memory leak. bestie. BESTIE. that memory is never coming back. it's a leak. π
β οΈ Caution β The functionszmq_msg_init(),zmq_msg_init_data(),zmq_msg_init_size()andzmq_msg_init_buffer()are mutually exclusive. Never initialise the samezmq_msg_ttwice. pick ONE. not two. never two. periodt. β
π RETURN VALUE π
zmq_msg_init_data() shall return zero if successful. otherwise it shall return -1 and set errno to one of the values defined below. zero = slay, -1 = check your errno, girl. β¨
π ERRORS π
ENOMEMβ Insufficient storage space is available. the storage is not storing. the space is not spaced. π
π EXAMPLE π
Initialising a message from a supplied buffer. look at her go π
void my_free (void *data, void *hint)
{
free (data);
}
/* ... */
void *data = malloc (6);
assert (data);
memcpy (data, "ABCDEF", 6);
zmq_msg_t msg;
rc = zmq_msg_init_data (&msg, data, 6, my_free, NULL);
assert (rc == 0);
see how my_free just goes poof and frees the data when 0MQ is done with it? that's the whole contract. that's the arrangement. iconic behaviour honestly. π₯
π SEE ALSO π
zmq_msg_init_size(3) zmq_msg_init_buffer(3) zmq_msg_init(3) zmq_msg_close(3) zmq_msg_data(3) zmq_msg_size(3) zmq(7)
like, go read the rest of the family, they're all connected, iykyk π«
π§ AUTHORS π§
This page was written by the 0MQ community. To make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing.
so yeah, it's a community thing, come contribute, we'd love to have you π«Ά
aaaaand that's the whole page babes πΈ this was 0MQ version 4.3.5, dated 10/09/2023, and the page is ZMQ_MSG_INIT_DATA(3) β mwah, stay leak-free, use your free function, and never init the same message twice π
β¨π
π¦ where this page comes from
- epel 10: zeromq 4.3.5-18.el10_0 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms