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 new SDL_AsyncIO to.
  • 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 must SDL_free() that buffer from SDL_AsyncIOOutcome's buffer field 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