'c++ paged byte queue
I was surprised how hard it is to implement an raw memory fifo. That is you push x number of bytes into the queue/fifo and then pop y out. The byte queue has few requirements:
- Paged. The queue storage is split into fixed sized blocks.
- Dynamic capacity.
- Iterable from oldest byte added to newest byte added. (forward iterators)
- Empty pages are either freed or recycled as new for push()
- Queue size can be computed.
My current existing code has bugs that I don't know how to fix. (I tried and failed) std::deque<> is the closest STL container but it doesn't provide access to the allocated memory as blocks/pages. It works poorly because the byte queue is used in ring-buffer fashion.
Most useful feature was the queue iteration: iterate(from, end, [](char*area,size_t n){}) that iterates the queue contents in as large chunks as possible.
Edit: For usage clarification: the memory pages may be registered for I/O operations. This means I can't easily deallocate said pages. E.g. std::deque<char> has unspecified page size. I don't know if it possible iterate it such that I know what ranges are infact contiguous in memory for memcpy() type of operations etc.
How do I implement such container or make better use of existing one?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
