iob_new_autofree(3)

πŸ’– iob_new_autofree(3) πŸ’–

okay so bestie, we're in the Library Functions Manual today and this one is literally the cutest little constructor. let's get into it 🫢


✨ NAME ✨

iob_new_autofree β€” creates a brand new I/O batch, but make it autofree πŸ‘‘


🌸 SYNTAX 🌸

#include <libowfat/iob.h>

io_batch* iob_new_autofree(size_t hint_entries);

πŸ¦‹ DESCRIPTION πŸ¦‹

so iob_new_autofree makes you a fresh new I/O batch, and it allocates enough space for hint_entries entries (those are buffers or files, bestie). key thing tho: this is purely a performance hint. don't stress about getting it perfect β€” if you're unsure, just pass 1 and move on with your day πŸ’…

the autofree flag gets set, which means resources get freed in iob_send once they've actually been sent out β€” not only when you call iob_reset or iob_free at the end. but no cap: you still have to call those. autofree only frees the resources to be sent in the batch, not the resources of the batch itself. so don't ghost iob_reset/iob_free or you'll be leaking, and that's not the vibe 😭

you can add buffers, strings and files to an I/O batch, then send the whole thing at once with iob_send. it's giving one big beautiful send ✨

the way the I/O batch API ate?? it exploits platform specific APIs like FreeBSD's sendfile. the file contents will always be sent in a way that lets the operating system do zero copy TCP, and the buffers will always be sent using as few syscalls as possible while avoiding unnecessary copying (via writev). iconic behavior, honestly 🌈


⭐ RETURN VALUE ⭐

iob_new_autofree returns a pointer to an I/O batch data structure. but if there was a memory allocation error, it returns NULL instead. so like, check it. always check it. πŸ™ˆ


πŸŽ€ SEE ALSO πŸŽ€


go read the whole friend group, they're all slaying in their own way πŸ’œ

and that's the whole page, bestie β€” straight outta the Library Functions Manual, filed under iob_new_autofree(3). mwah, go write some zero-copy code πŸ§šπŸ’–

πŸ“¦ where this page comes from