Jump to content
  • Advertisement
Sign in to follow this  
Kitt3n

event handler system

This topic is 4117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm was googling a bit for event handlers and systems, read several approaches and have a few questions (obviously :) So we have an event-base class and our event-dispatches class has a function where we post the event (input = a reference or maybe pointer to the event-instance we wanna post). Now I'd like to store the event in the dispatcher (in an stl-container) Now the question is what type should the data stored in the list be? I came up with the following possibilities 1. Smart pointers (avoid the new/copy of the event, when it goes out of scope, the event-handler will keep the ownership. 2. pointer to event (copied in 'postEvent' over event->clone') 3. Some stream (generated in 'postEvent' over event->save'). Solution 1 probably has the least overhead, but I'm a little bit 'afraid' to use smart pointers (Boost is a bit overwhelming I think) I also don't know exactly what to take (there are several kinds with different ownership semantics - and I read the stl-smart pointer isn't that great)... Any code-snippets maybe? To 2, it will have a 'new' in the clone method which would generate some overhead... Might be reduced by memory-pooling system. To 3. Already implemented sth like that, and seems to work (has some overhead, although not yet appeared in VTune as a hotspot, so seems okay). Still curious for alternatives :) ... are there any alternatives which I didn't list? Thanks !

Share this post


Link to post
Share on other sites
Advertisement
If its not appearing in the profiler and the solution isn't too ugly I would spend my time elsewhere :)

About smart pointers:

You mentioned "stl-smart pointer". I guess you mean std::auto_ptr. This can not be stored safely in containers and is basically used for two things:
1. providing exception-safe cleanup of memory
2. making transfer of ownership of a pointer more obviously visible.
The classic link covering this: Using auto_ptr effectively.

Boost has a couple, but the absolute most important one is boost::shared_ptr. It is the general purpose shared pointer and all the others are for special cases (you probably won't need).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!