mardi 7 juillet 2020

What is the most optimal way to store eventHandlers inside reactor

Folks, what would be the most optimal data structure to store eventHandlers in the reactor class. A few details about the event handler. Every event handler can be registered to listen for a specific event type. Event is a class which has got int32_t type and the virtual method OnMessage(const Message*). Something like this

class IEventHandler
{
  int32_t type;
public:
  virtual ~eventHandler() {};
  virtual void OnMessage(const Message *msg) = 0;
};

Can I just store event handlers in the vector and sort them by the message type to optimize the search process when event is received or I need to store these in the map. I am trying to find the fastest way to find an event and call an event handler. When I insert an event I can use std::lower_bound to find the proper position of the event handler in the vector.

Thanks, folks

Aucun commentaire:

Enregistrer un commentaire