SDL_RWOps flexibility

Hi,

I’m implementing a function to read the contents of a file using SDL_RWOps.
I looked at the code and the way one has to initialize a SDL_RWOps context
forces a heap memory allocation (SDL_AllocRW) and deallocation (SDL_FreeRW).

I want to avoid the allocation. Any reason for not providing a function
that accepts an existing SDL_RWOps pointer and initializes it?

{
SDL_RWops ops;
new_SDL_RWFromFile(&ops, filename, “r”);

}

This way I could reuse the SDL_RWOps when dealing with multiple files
without allocating/deallocating memory every time.

The current API could be implemented as an special case: pass the
SDL_malloc’d SDL_RWOps to new_RWOpsFrom*.–
Felipe

You do realize that opening a file usually involves several memory
allocations even without SDL_RWOps, right?On 08.01.2015 05:17, Felipe Oliveira Carvalho wrote:

Hi,

I’m implementing a function to read the contents of a file using SDL_RWOps.
I looked at the code and the way one has to initialize a SDL_RWOps context
forces a heap memory allocation (SDL_AllocRW) and deallocation (SDL_FreeRW).

I want to avoid the allocation. Any reason for not providing a function
that accepts an existing SDL_RWOps pointer and initializes it?

{
SDL_RWops ops;
new_SDL_RWFromFile(&ops, filename, “r”);

}

This way I could reuse the SDL_RWOps when dealing with multiple files
without allocating/deallocating memory every time.


Rainer Deyke (rainerd at eldwood.com)

My suggestion would be that the RWops interface reflects the way all of the
other interfaces in SDL work (see also SDL_CreateRGBSurface(),
SDL_CreateWindow(), etc.). Structures meant to be used as mostly or
completely opaque are dynamically allocated and a pointer is returned.
Structures used more like value types (e.g. SDL_Rect) have the flexibility
to be on the stack.

SDL might not do as much on the stack as is possible, but it surely is more
directly portable to other language bindings.

Jonny DOn Fri, Jan 9, 2015 at 3:06 AM, Rainer Deyke wrote:

On 08.01.2015 05:17, Felipe Oliveira Carvalho wrote:

Hi,

I’m implementing a function to read the contents of a file using
SDL_RWOps.
I looked at the code and the way one has to initialize a SDL_RWOps context
forces a heap memory allocation (SDL_AllocRW) and deallocation
(SDL_FreeRW).

I want to avoid the allocation. Any reason for not providing a function
that accepts an existing SDL_RWOps pointer and initializes it?

{
SDL_RWops ops;
new_SDL_RWFromFile(&ops, filename, “r”);

}

This way I could reuse the SDL_RWOps when dealing with multiple files
without allocating/deallocating memory every time.

You do realize that opening a file usually involves several memory
allocations even without SDL_RWOps, right?


Rainer Deyke (rainerd at eldwood.com)


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