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 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 like, if you don't set it, nobody's cleaning up for you, k? πŸ™ˆ

πŸ‘‘ FUNCTION PARAMETERS πŸ‘‘

  • mem β€” a pointer to a buffer to feed an SDL_IOStream stream.
  • 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 πŸ“


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