disruptor--
disruptor-- copied to clipboard
is std::array a good container to RingBuffer due to limited stack size?
Typically a process' stack size is quite small (a few mega bytes). For example, it's 8MB on Mac. Think we can increase that, but it's not ideal if a program has 10s or 100s threads because each thread will consume that amount of memory reserved for stack.
also the side effect of std::array is that it requires a default constructor on T.
isn't std:array allocated on stack only if the underlaying ring-buffer is allocated on the stack?
Yes, but does not sound good if a class can only be used on heap, but not on stack due to big array. For example below code will get core dump on Mac (default max stack size is 8MB) and Linux (default max stack size is 10MB) because of 'A a;'
#include <iostream>
#include <array>
struct A {
std::array<int, 1<<22> mem;
};
int main() {
auto* p = new A;
A a;
std::cout << "done" << std::endl;
}