I have written a circular buffer with static capacity, therefore it is backed by a (constant size) array. It is owned by a singleton class allocated on the heap. My question is whether or not the backing array in the circular buffer should be inline, or allocated on the heap. The difference would be:
CircularBuffer
{
std::array<uint64_t, N> buffer;
}
CircularBuffer
{
uint64_t* buffer;
}
To be clear, allocation will happen once at startup, and everything will be on the heap, as the enclosing object will be heap allocated. Also, each portion of the buffer will be accessed an equal amount of times due to the nature of the data structure and its usage.
Theoretically, what would you consider in making this decision, if your goal is performance?
Of course I will make my final decision based on benchmarks. But as a first pass, the parameters I am considering are:
- N: Size of buffer
- R: What percentage of calls to the enclosing object result in reads/writes to the buffer
In practice, N = 1MB, R = 100% (all calls result in both a read and write to the buffer), and I am running single threaded on a high end cpu.
Are there other parameters you would consider?