Does SDL_RWops make an internal copy of memory?

In the function SDL_RWFromMem(void *mem, int size)

Will SDL_RWFromMem make a copy of ‘mem’, or is the array referenced from the
SDL_RWops object and cannot therefore be freed?

Thanks,

  • Luke

Hello,

It’s referenced, so you’ll need to keep it allocated until you call
SDL_RWclose (or the loading function does).

On Windows at least, it wouldn’t be safe for the SDL DLL to free
memory allocated outside of it, as they can have different runtime
libraries (and associated memory managers).

It’s the same sort of deal with FILE*s too if I remember correctly. I
seem to recall getting bitten by that one time in a non-SDL project.

Hope this helps,

Peter

2008/7/20 Luke Crook :>

In the function SDL_RWFromMem(void *mem, int size)

Will SDL_RWFromMem make a copy of ‘mem’, or is the array referenced from the
SDL_RWops object and cannot therefore be freed?

Thanks,

  • Luke

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Peter Mackay <mackay.pete+sdl gmail.com> writes:

Hello,

It’s referenced, so you’ll need to keep it allocated until you call
SDL_RWclose (or the loading function does).

On Windows at least, it wouldn’t be safe for the SDL DLL to free
memory allocated outside of it, as they can have different runtime
libraries (and associated memory managers).

It’s the same sort of deal with FILE*s too if I remember correctly. I
seem to recall getting bitten by that one time in a non-SDL project.

Thanks. This confirms the behaviour I am seeing in my code.

  • Luke