[SDL] structs returned by pointers
bob at pendleton.com
Sun Apr 25 14:34:33 PDT 2004
On Sat, 2004-04-24 at 15:52, Jeff Schiller wrote:
> Are SDL_Surface structs, SDL_VideoInfo structs and anything else returned by
> pointer via SDL function calls automatically cleaned up by SDL afterwards
> inside SDL_Quit, or should I be calling delete/free on these pointers (I
> assume free since SDL is written in C)? I've just started using SDL so I
> haven't had a chance to dig into the source or detect memory leaks with my
You need to read the documentation for each function that returns a
value. While it isn't always clear... they do give you hints about what
to do with the pointers returned by SDL functions.
For example: the documentation for SDL_SetVideoMode() states that the
structure will be cleaned up by SDL_Quit(). Other structures are
mentioned to be "read only" that usually means that they are actually
static structures that don't need to be cleaned up.
Another example are the create surface functions. Those functions have a
related function named SDL_FreeSurface() that you must use to free a
surface. In general, if a structure returned by an SDL function needs to
be cleaned up by the programmer there is a "free" function provided for
the task. Those free functions understand the internal details of the
structure and are needed to do a complete cleanup that just calling
free() would not do.
I understand the frustration you are facing, a lot of information in the
documentation is not spelled out as explicitly as it could be. But, if
you read it carefully it is there. :-)
> FREE pop-up blocking with the new MSN Toolbar get it now!
> SDL mailing list
> SDL at libsdl.org
+ Bob Pendleton: writer and programmer. +
+ email: Bob at Pendleton.com +
+ web: www.GameProgrammer.com +
More information about the SDL