I want to have a c++ first-in first-out queue structure. What should I be using for this?
There is a std::queue, I’m not sure if you are asking about C++ or an Unreal Container that is a queue.
Yes there are some:
TQueue<> located in Source\Runtime\Core\Public\Misc\Queue.h
TCircularQueue<> located in Source\Runtime\Core\Public\Misc\CircularQueue.h
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!
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?
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.
Hello, I know this thread is a bit old but I have a question regarding the queues and hope someone is still reading this.
Only TArray can have the UPROPERTY macro telling the GC not to touch any objects pointed to from the array. As for TMap and TSet you can tell the GC not to touch their content either using the static function AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector) and call Collector.AddReferencedObjects(…). This however seems to not work for TQueue. My question then is how you avoid stuff pointed to from the TQueue from being GC’ed?
TMap can be be UPROPERTY(), so you don’t need to explicitly tell GC to do not touch it’s elements.
Hello. I see. TMap having UPROPERTY() must be a never feature? I used the explicit method back in 4.4 or 4.5 don’t remember which though. Regardless what do you do with the TQueue? It cannot have UPROPERTY() nor can you explicitly tell the GC not to touch it. At least not with the Collector.AddReferencedObjects(…) function.