简体   繁体   English

std :: bitset中的元素数量是否有最大值?

[英]Is there a maximum to the number of elements in std::bitset?

Is there a maximum to the number of elements in an std::bitset ? std::bitset的元素数量是否有最大值?

In my code (VC++2010) 1<<20 crashes with a stack overflow, but 1<<19 works. 在我的代码(VC ++ 2010)中, 1<<20因堆栈溢出而崩溃,但1<<19可以工作。

(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. 据我看到这无关与负载元素的最大数bitset ,但有可以在堆栈分配的内存量做。 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. 通常,在VS上,可在堆栈上分配的最大内存为1 MB,如果超过此限制,则会出现堆栈溢出。 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. 如果您需要的内存超过此数量,则建议使用new从堆中分配内存,而不是在堆栈上进行分配。 In such case, the memory allocation will fail only when new truly runs out of memory. 在这种情况下,只有当new真正用完内存时,内存分配才会失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM