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.)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I see this has nothing to do with the maximum number of elements supported in
bitsetbut 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 usingnewrather than allocating on stack. In such case, the memory allocation will fail only whennewtruly runs out of memory.