Original Post
Hi, I want to make my engine multithreaded, so for that I would be using a message/command queues mechanism. My question is, for example the logic thread fills a queue for the render thread to draw, is STL fast enough or should I make a flat memory buffer which will be used as a pool, with rare realloc of memory, baring in mind that this command queue will be filled several times per second, and I dont know if push_back() will be fast enough. Other thing good when you have a linear buffer where you store command data is that you dont need to alloc a specific class for each command type, example:
class QueueCommand
{
public:
int m_id;
}
class SetRenderStateCommand: public QueueCommand
{
public:
int m_someCmdSpecificMember1;
int m_someCmdSpecificMember2;
}
Methods to store the queue commands:
1. STL -> deque<QueueCommand*> m_queue; // bad, we must have pointers
because we need different command types, with different sizes, too much small
allocs; one workaround is to make the QueueCommand same size for all the
command types, and just to have a class for all IDs like:
class RenderCommand
{
int m_commandId;
float m_param1,m_param2,m_param3,... until a maximum of params you settle on
}
and then you can have a: deque<RenderCommand> m_queue; // no pointer now,
we have a constant size of the command data, OR we can use a memory pool manager for all those small allocs.
2. Flat buffer -> char* m_queue; // good, no more small allocs, just fill
this buffer with command IDs and command params, but its a little tricky to pop
commands, needs a memory move operation when a command is popped from the queue
Thanks for any oppinion.