Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
derekxgl opened this issue Jan 6, 2016 · 3 comments
Open

Comments

@derekxgl
Copy link

derekxgl commented Jan 6, 2016

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
Copy link
Author

derekxgl commented Jan 6, 2016

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

@fsaintjacques
Copy link
Owner

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

@derekxgl
Copy link
Author

derekxgl commented Jan 7, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants