Is there a maximum to the number of elements in an std::bitset
?
In my code (VC++2010) 1<<20
crashes with a stack overflow, but 1<<19
works.
(I'm dealing with huge inputs.)
Is there a maximum to the number of elements in an std::bitset
?
In my code (VC++2010) 1<<20
crashes with a stack overflow, but 1<<19
works.
(I'm dealing with huge inputs.)
As far as I see this has nothing to do with the maximum number of elements supported in bitset
but has to do with the amount of memory that can be allocated on stack. On VS normally, the maximum memory that can be allocated on stack is 1 MB and if you cross this limit then you get stack overflow. If you require more than this amount of memory, then I would suggest to allocate memory from heap using new
rather than allocating on stack. In such case, the memory allocation will fail only when new
truly runs out of memory.