Hello, I am wondering if there is any constraint on using TCircularQueue.
For example, TCircularQueue::Enqueue is defined as following
const uint32 CurrentTail = Tail.Load();
uint32 NewTail = Buffer.GetNextIndex(CurrentTail);
if (NewTail != Head.Load())
{
Buffer[CurrentTail] = Element; // <- actual insertion
Tail.Store(NewTail);
return true;
}
return false;
Buffer is defined as TCircularBuffer which is just a thin wrapper for TArray.
Here is the implementation of TCircularBuffer ctor.
explicit TCircularBuffer(uint32 Capacity)
{
checkSlow(Capacity > 0);
checkSlow(Capacity <= 0xffffffffU);
Elements.AddZeroed(FMath::RoundUpToPowerOfTwo(Capacity));
IndexMask = Elements.Num() - 1;
}
It calls TArray::AddZeroed to claim required capacity and according to the documentation AddZeroed created elements without calling ctors.
Now my concern is that if I enqueue an object into TCircularQueue, wouldn’t that be problematic to just copy assign it to a bunch of raw memory where the ctor has not been called?
Or is there something I’ve missed?