B
brekehan
I am implementing a event messaging system. Basically I do:
---update cycle---
processing/check for new events
allocate a new event
put it in a std::queue
Dispatch events
make an event equal to std::queue.front()
pop an event from the std::queue
get its type
send it off to registered handlers
Now problem is that the handler may or may not process it. The handler
will return me a 0 if it was taken care of and a 1 if not. If the
event was not handled I want to leave it to be dispatched again next
update cycle. A std::queue only has a front() function, but no
iterator. So I cannot get the event, decide if I still want it or not,
then go to the next event without getting rid of the first. I cannot
iterate through and choose to erase handled events.
First I considered making another queue and putting unhandled events
into it then copying that queue to the original, but I think that
would be darn expensive, no?
I also considered using a vector instead of a queue, so I can iterate
through and erase as I need to, but isn't a vector more expensive,
especially since I am looking at the front and erasing in random
places?
Any other ideas for a more efficient event queue?
---update cycle---
processing/check for new events
allocate a new event
put it in a std::queue
Dispatch events
make an event equal to std::queue.front()
pop an event from the std::queue
get its type
send it off to registered handlers
Now problem is that the handler may or may not process it. The handler
will return me a 0 if it was taken care of and a 1 if not. If the
event was not handled I want to leave it to be dispatched again next
update cycle. A std::queue only has a front() function, but no
iterator. So I cannot get the event, decide if I still want it or not,
then go to the next event without getting rid of the first. I cannot
iterate through and choose to erase handled events.
First I considered making another queue and putting unhandled events
into it then copying that queue to the original, but I think that
would be darn expensive, no?
I also considered using a vector instead of a queue, so I can iterate
through and erase as I need to, but isn't a vector more expensive,
especially since I am looking at the front and erasing in random
places?
Any other ideas for a more efficient event queue?