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 the mem parameter that was passed to this function.
  • SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER β€” this will be the size parameter 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-NULL value it will be interpreted as a function of SDL_free_func type and called with the passed mem pointer 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 an SDL_IOStream stream. 🌸
  • 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