SDL_IOFromMem(3)
π SDL_IOFromMem β bestie, we're making a memory buffer into a stream π
okay so real talk, this page lives in the SDL3 FUNCTIONS corner of the manual and it's literally called SDL_IOFromMem(3). Let's get into it π«Ά
β¨ NAME β¨
SDL_IOFromMem β use this function to prepare a read-write memory buffer for use with SDL_IOStream. that's the whole job description bestie, she's a preparer π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_iostream.h>
SDL_IOStream * SDL_IOFromMem(void *mem, size_t size);
π¦ DESCRIPTION π¦
so this function sets up an SDL_IOStream struct based on a memory area of a certain size, and it's for both read and write access. like, both. she does it all π
β οΈ THE BIG ONE, NO CAP: this memory buffer is not copied by the SDL_IOStream. the pointer you provide must remain valid until you close the stream. periodt. if your buffer dips out early, that's on you π
if you need to make sure the SDL_IOStream never writes to the memory buffer, you should use SDL_IOFromConstMem() with a read-only buffer of memory instead. that's the safety-girl option, and honestly? iconic π
the following properties will be set at creation time by SDL:
SDL_PROP_IOSTREAM_MEMORY_POINTER: this will be thememparameter that was passed to this function.SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER: this will be thesizeparameter that was passed to this function.
additionally, the following properties are recognized:
SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER: if this property is set to a non-NULLvalue it will be interpreted as a function ofSDL_free_functype and called with the passedmempointer when closing the stream. by default it is unset, i.e., the memory will not be freed. so like, if you don't set it, nobody's cleaning up for you, k? π
π FUNCTION PARAMETERS π
memβ a pointer to a buffer to feed anSDL_IOStreamstream.sizeβ the buffer size, in bytes.
β RETURN VALUE β
returns a pointer to a new SDL_IOStream structure or NULL on failure. and if you get that NULL? call SDL_GetError() for more information. she'll tell you what went wrong, bestie π
π THREAD SAFETY π
it is safe to call this function from any thread. yes queen, thread-safe, we love to see it π₯
π§ AVAILABILITY π§
this function is available since SDL 3.2.0. so if you're on something older... no she's not there yet π
π SEE ALSO π
SDL_IOFromConstMem(3)SDL_CloseIO(3)SDL_FlushIO(3)SDL_ReadIO(3)SDL_SeekIO(3)SDL_TellIO(3)SDL_WriteIO(3)
and that's the whole page, bestie!! β¨ this little love letter comes to you from Simple Directmedia Layer, version SDL 3.4.18, and the page itself is SDL_IOFromMem(3). go make a memory buffer into a stream, you've 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