Is there a FIFO queue somewhere?

I want to have a c++ first-in first-out queue structure. What should I be using for this?

1 Like

There is a std::queue, I’m not sure if you are asking about C++ or an Unreal Container that is a queue.

http://www.cplusplus.com/reference/queue/queue/

Yes there are some:

TQueue<> located in Source\Runtime\Core\Misc\Queue.h
TCircularQueue<> located in Source\Runtime\Core\Misc\CircularQueue.h

johnflux,

Use TQueue<> for FIFO collections. It is thread-safe and lock and contention free for single-producer-single-consumer. If you have to add to the queue from multiple threads, you can use TQueue<EQueueMode::Mpsc>, which is lock-free for multiple producers, but not contention free (it uses a CAS to synchronize access).

TCircularQueue<> queue has better memory allocation behavior, because it uses a pre-allocated TArray for item storage. However, the number of items you can queue up is limited to the Size you create it with. TQueue has no such limitation. TCircularQueue<> is currently not used in the Engine, but should work. If you encounter any problems, please IM me or post on AnswerHub, thanks!

2 Likes

Is it possible to expose TQueues to Blueprints? Is there an example of how to expose them as a UPROPERTY?

Would it be expedient to just create a UOBJECT wrapper?

1 Like

That’s an interesting proposition. I will discuss it with our Blueprint guys.

Cool, let us know what the decisions is. I normally wouldn’t bother, but having queues appear in the content browser and blueprints could help a lot by having access to a canonical queue implementation as well as debugging in blueprints.

Hello, I stumbled onto this from google today. is there any news on a way to expose Queues, Circular Queues, or even a custom class like this to blueprints?
I especially make extensive use of circular queues and I tend to flatten them to TArray to output them to blueprints but that seems horribly inefficient. I would love nothing more than to delete all of that code.

1 Like

TMap can be be UPROPERTY(), so you don’t need to explicitly tell GC to do not touch it’s elements.

TQueue == Uses Lock Free Linked List (SPSC, MPSC), elements are newed/deleted
TCircularQueue == Lock Free SPSC, Sequential, Capacity is fixed
TDeque == Sequential, Dynamically sized
TRingBuffer == Sequential, Dynamically Sized