disruptor-- icon indicating copy to clipboard operation
disruptor-- copied to clipboard

is std::array a good container to RingBuffer due to limited stack size?

Open derekxgl opened this issue 9 years ago • 3 comments

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.

derekxgl avatar Jan 06 '16 21:01 derekxgl

also the side effect of std::array is that it requires a default constructor on T.

derekxgl avatar Jan 06 '16 22:01 derekxgl

isn't std:array allocated on stack only if the underlaying ring-buffer is allocated on the stack?

fsaintjacques avatar Jan 07 '16 03:01 fsaintjacques

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;
}

derekxgl avatar Jan 07 '16 11:01 derekxgl