COROIO: coroio/actors/queue.hpp File Reference
COROIO
Loading...
Searching...
No Matches
queue.hpp File Reference

Memory-efficient unbounded queue implementation for actor message passing. More...

#include <vector>

Go to the source code of this file.

Classes

struct  NNet::NActors::TUnboundedVectorQueue< T >
 Unbounded queue with automatic capacity growth. More...

Detailed Description

Memory-efficient unbounded queue implementation for actor message passing.

This file contains a queue implementation that avoids the memory allocations/deallocations of std::queue (which uses std::deque). The queue uses a single vector with power-of-two sizing and bitwise operations for fast indexing, growing only when necessary.

Basic Usage Examples

Basic Queue Operations

TUnboundedVectorQueue<int> queue;
// Add elements
queue.Push(42);
queue.Push(100);
// Process elements
while (!queue.Empty()) {
int value = queue.Front();
queue.Pop();
processValue(value);
}

Actor Message Queue

TUnboundedVectorQueue<TEnvelope> messageQueue(64); // Start with 64 capacity
// Producer (actor system)
messageQueue.Push(TEnvelope{sender, recipient, messageId, blob});
// Consumer (actor)
if (!messageQueue.Empty()) {
auto& envelope = messageQueue.Front();
actor->Receive(envelope.MessageId, envelope.Blob, ctx);
messageQueue.Pop();
}