Archived

This topic is now archived and is closed to further replies.

stodge

Use the STL priority_queue or write my own version?

Recommended Posts

I''m already using a number of STL containers in my engine, but I was wondering if people thought the priority_queue was worth using for an event queue. Or does it not work too well (for whatever reason) and I should consider writing my own? Each event in the engine has a priority (system, high, medium and low). As an alternative I was thinking of using 1 STL queue container for each queue and just managing priorities myself. Any thoughts? Thanks

Share this post


Link to post
Share on other sites
It works great. However, beware the default version using less as a predicate will give you the greatest element first. I found this counter-intuitive, but once you know you''re off & running.

Think Liberally..

Share this post


Link to post
Share on other sites
Well, std:: priority_queue is O(log N). With 4 separate queues in an array you can easily archieve O(1) performance. But before doing it, think if std:: priority_queue is enough for your needs. I.e. If you need the priority queue quite rarely, like only 100 times / second, it'll most likely be fast enough. (I just had to say that before someone comes to warn me about the evilness of premature optimization)

edit: damn smileys

[edited by - civguy on January 29, 2003 7:23:57 PM]

Share this post


Link to post
Share on other sites
I don''t mind using STL for ADTs that I use for holding data that will not be used during the running loop of the engine. (e.g. Texture management, Sprite Management etc) The reason for this I view STL as not Optimized for MY specific need. So i tend to program my own when I use stacks/lists/whatever if they are being used in a realtime environment, but using STL in loading environment and to hold and manage data is fine, but in a realtime situation writing your own can be much better.

In general STL is good but I don''t prefer to use it in a game loop.

I know this may not answer some of the more specific answers on how you should manager your queue, but you know you want that to work better than I.

-Syntax

Share this post


Link to post
Share on other sites