SDL_IOFromConstMem(3)
π SDL_IOFromConstMem(3) π
okay bestie, welcome to the <SDL3/SDL_iostream.h> chapter of the SDL3 FUNCTIONS manual β this one's called SDL_IOFromConstMem, and it's giving "i have some memory and i want to read it, not touch it" energy. let's go π¦
β¨ NAME β¨
SDL_IOFromConstMem β the function you use to prep a read-only memory buffer so an SDL_IOStream can vibe with it. no writing, just reading, periodt. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_iostream.h>
SDL_IOStream * SDL_IOFromConstMem(const void *mem, size_t size);
π DESCRIPTION π
so like, this function sets up an SDL_IOStream struct based on a memory area of a certain size. it assumes the memory area is not writable. that's the whole bit. it's read-only and it knows it. π
if you try to write to this SDL_IOStream stream, it will report an error and not write anything to the memory buffer. not me trying to write to read-only memory π it's literally not happening.
β οΈ big one: this memory buffer is not copied by the SDL_IOStream. the pointer you provide must remain valid until you close the stream. if that pointer dips out early, that's on you, fr fr. π
if you actually do need to write to a memory buffer, you should use SDL_IOFromMem() with a writable buffer of memory instead. different function, different vibe. π
the following properties get 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 no sneaky auto-cleanup unless you ask for it, iykyk. π§
π«Ά FUNCTION PARAMETERS π«Ά
memβ a pointer to a read-only buffer to feed anSDL_IOStreamstream. πΈsizeβ the buffer size, in bytes. numbers matter bestie, don't skip it. β¨
π RETURN VALUE π
returns a pointer to a new SDL_IOStream structure, or NULL on failure β and if it's NULL, call SDL_GetError() for more info. always check, always. π₯
π THREAD SAFETY π
it is safe to call this function from any thread. go wild, multitask, slay. π
π AVAILABILITY π
this function is available since SDL 3.2.0. vintage-ish but iconic. β
π SEE ALSO π
and that's the whole page, bestie π this lil' rewrite was brought to you by Simple Directmedia Layer, from the SDL 3.4.18 era of the SDL3 FUNCTIONS collection. go forth and read-only, my main character. π¦πβ¨
π¦ 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