Skip to main content
GameDev.net gamedev.net
🔒 Locked

Question on size/cost of SDL Event type

Started by triqer Nov 11, 2009 at 10:10 PM 5 replies 1.4k views
Original Post
triqer
triqer
Is it expensive to have an SDL Event as a local variable in a function that is called numerous times? I.e. does the creation of an SDL Event have any significant performance implications?
Ezbez
Ezbez
In general; not a chance.

However, you might have a special case. Luckily, there's a simple way to know - test it. Write it with local SDL_Event variables, see if it hurts your performance It almost certainly won't, in which case you're done and you go happily along with your life. If it does hurt performance, try to figure out what exactly is causing the slow down. Maybe you're calling the function too many times, maybe the construction of the SDL_Event is taking too much, maybe it's unrelated to the SDL_Event. Measure the effects, and you will know. Without measurements, all we can do is say probably.

BTW, these kinds of things rarely make a difference unless you're doing them thousands of times a frame.
triqer
triqer
Thanks. I was slightly worried that since SDL_Event is such an integral part of the SDL library that it would end up being some massive object that is extremely expensive to create.
triqer
triqer
Quote:
Original post by Palidine
[google]: SDL_Event: http://sdl.beuc.net/sdl.wiki/SDL_Event

it's tiny

-me


Obviously I went to that page, but unless I'm missing something it doesn't give any information regarding the amount of memory it takes up.

Sneftel
Sneftel
Quote:
Original post by triqer
Obviously I went to that page, but unless I'm missing something it doesn't give any information regarding the amount of memory it takes up.

Quote:

typedef union{ // In other words, I take up only as much space as the largest of my members!
Uint8 type; // I'm pretty small
SDL_ActiveEvent active; // Apparently I'm 3 bytes
SDL_KeyboardEvent key; // And I'm probably pretty small too
SDL_MouseMotionEvent motion; // etc... how much data could any of these really have?
SDL_MouseButtonEvent button;
SDL_JoyAxisEvent jaxis;
SDL_JoyBallEvent jball;
SDL_JoyHatEvent jhat;
SDL_JoyButtonEvent jbutton;
SDL_ResizeEvent resize;
SDL_ExposeEvent expose;
SDL_QuitEvent quit;
SDL_UserEvent user;
SDL_SysWMEvent syswm;
} SDL_Event;
In any case -- and this is the more important point -- the size of a structure does not affect the time needed to allocate it as a local variable. Stack allocations are basically free.
SiCrane
SiCrane
It does, but you need to click a dozen different links to get a full picture of the size. It'd just be easier to compile an SDL console app and output sizeof(SDL_Event).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.