SDL_LoadFileAsync(3)
β¨ SDL_LoadFileAsync(3) β¨
okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, this one's from the SDL_asyncio.h cinematic universe and it's genuinely such a vibe π
πΈ NAME πΈ
SDL_LoadFileAsync β grab every last byte of a file from a path, but asynchronously, so you're not just sitting there waiting like π§
π¦ SYNOPSIS π¦
#include <SDL3/SDL_asyncio.h>
bool SDL_LoadFileAsync(const char *file, SDL_AsyncIOQueue *queue, void *userdata);
π DESCRIPTION π
so the whole point of this one: it returns as quickly as possible. it does not wait for the read to finish. on a successful return, the work just keeps chugging along in the background, living its little life, main character energy, no notes β¨
and here's the part that trips people up: if the work begins, then even failure is asynchronous. a failing return value from this function only means the work couldn't start at all. like, that's it. that's the whole message. so don't read too much into a false, fr fr π
the data comes allocated with a zero byte at the end (null terminated) for convenience, because they're looking out for you π«Ά but heads up β that extra byte is not included in SDL_AsyncIOOutcome's bytes_transferred value. don't count it, bestie, it's a bonus byte.
this function will allocate the buffer to hold the file. which means you gotta deallocate it yourself by calling SDL_free() on SDL_AsyncIOOutcome's buffer field after completion. yes, it's yours now. it's your child. take care of it π
an SDL_AsyncIOQueue must be specified. the newly-created task gets added to it once it finishes doing its thing.
π FUNCTION PARAMETERS π
fileβ the path to read all available data from. yes, all of it. every crumb.queueβ a queue to add the newSDL_AsyncIOto.userdataβ an app-defined pointer that will be provided with the task results. it's your little note-to-self that comes back to you later, iconic π
β RETURN VALUE β
returns true on success or false on failure; call SDL_GetError() for more information. (and remember the rule from above β a false here just means it couldn't start.) π
π THREAD SAFETY π
it is safe to call this function from any thread. go wild, no cap π
β¨ AVAILABILITY β¨
this function has been available since SDL 3.2.0. she's not new new, but she's still fresh π
π SEE ALSO π
π«Ά friendly reminder bestie: you mustSDL_free()that buffer fromSDL_AsyncIOOutcome'sbufferfield after completion. the null terminator byte is a gift, but the buffer is a responsibility. periodt.
and that's the tea, written up for Simple Directmedia Layer's SDL 3.4.18 era of the docs β mwah, go read some files asynchronously, you got this πβ¨ππ¦πΈ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms