Hi,
is there some possibility to let SDL track the number of pictures
i created against the number i’ve free’d?
Or let SDL give me a number of at the moment allocated pics?
If not, would that be a useful extension for 1.2.11 ?
Best regards,
Torsten.
Hello !
is there some possibility to let SDL track the number of pictures i
created against the number i’ve free’d?
Or let SDL give me a number of at the moment allocated pics?
If not, would that be a useful extension for 1.2.11 ?
You can count that yourself, there are also some
tools that can help you to find memleaks in your code.
Valgrind for example is such a tool.
CU
Hi,
is there some possibility to let SDL track the number of pictures
i created against the number i’ve free’d?
Or let SDL give me a number of at the moment allocated pics?
If not, would that be a useful extension for 1.2.11 ?
This is a fairly common programming problem that can be solved by simply
counting the number of images you have created and the number you have
freed. IMHO, it does not belong in SDL.
If you want to get really complicated and are using a language such as C
++ you can wrap the whole process in a class and use smart pointers to
manage deallocation for you.
Bob PendletonOn Wed, 2006-05-17 at 20:44 +0200, Torsten Mohr wrote:
Best regards,
Torsten.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
–
±-------------------------------------+
Or just use one of the many already out that already written that do
this for you, if your license is compatible.On Wed, May 17, 2006 at 03:51:45PM -0500, Bob Pendleton wrote:
If you want to get really complicated and are using a language such as
C ++ you can wrap the whole process in a class and use smart pointers
to manage deallocation for you.
–
Steaphan Greene
GPG public key: http://www.cs.binghamton.edu/~sgreene/gpg.key.txt
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060517/412e985c/attachment.pgp
Another simple solution would be to wrap the SDL image creation functions in
your own code that does some rudimentary tracking… takes very little code
to do so.
IE:
int sdl_surfaces_allocated;
SDL_Surface * foo_create(params)
{
SDL_Surface * meh;
meh = SDL_createasurface(params);
// meh checking goes here
sdl_surfaces_allocated++;
}
void foo_destroy(params)
{
SDL_destroyasurface(params);
sdl_surfaces_allocated–;
}
-WillOn 5/17/06, Steaphan Greene wrote:
On Wed, May 17, 2006 at 03:51:45PM -0500, Bob Pendleton wrote:
If you want to get really complicated and are using a language such as
C ++ you can wrap the whole process in a class and use smart pointers
to manage deallocation for you.
Or just use one of the many already out that already written that do
this for you, if your license is compatible.
–
Steaphan Greene
GPG public key: http://www.cs.binghamton.edu/~sgreene/gpg.key.txt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFEa5Ti/8a2QaBMG3YRAnZdAJwLCpiPu4shEEyxWKBWA7LiDyep6QCgjmjQ
EzUrC+w3zKHU9LA+2nV9neU=
=Ruqa
-----END PGP SIGNATURE-----
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
Or just use one of the many already out that already written that do
this for you, if your license is compatible.
Or do something like:
#define SDL_FreeImage mySDL_FreeImage
[…]
void mySDL_FreeImage(SDL_Surface *surf)
{
total_allocated_pictures–;
#undef SDL_FreeImage
SDL_FreeImage(surf);
}
There’s a lot of good/interesting ways to track this, but none of them
belong in SDL itself.
–ryan.
I find that Boost intrusive_ptr works very well for this kind of thing.
http://www.boost.org/libs/smart_ptr/intrusive_ptr.html
typedef boost::intrusive_ptr<SDL_Surface> surface_ptr;
void intrusive_ptr_add_ref(SDL_Surface* surface)
{
++surface->refcount;
}
void intrusive_ptr_release(SDL_Surface* surface)
{
SDL_FreeSurface(surface);
}
You can also use it to wrap DirectX/COM objects and so on.
Pete