[英]g++ out of memory allocating for std::bitset
Here I'm allocating 10^9 bits:这里我分配了 10^9 位:
#include <bitset>
#include <iostream>
const int N = 1000000000;
std::bitset<N> b;
int main()
{
std::cout << sizeof(b) << std::endl;
}
I get cc1plus.exe: out of memory allocating 268439551 bytes
.我得到
cc1plus.exe: out of memory allocating 268439551 bytes
。
But when I do但是当我这样做时
#include <bitset>
#include <iostream>
const int N = 1000000000;
int l[N/32];
int main()
{
std::cout << sizeof(l) << std::endl;
}
The 125000000 bytes (125 MB) are allocated fine. 125000000 字节(125 MB)分配得很好。 If I change
N
to a different power of 10 I see both sizeof
are the same.如果我将
N
更改为 10 的不同幂,我会看到两个sizeof
是相同的。 I don't even see where the 268439551 byte limit is coming from, since that's 268.4 MB and I have about 4 GB RAM free.我什至看不到 268439551 字节限制的来源,因为这是 268.4 MB,而且我有大约 4 GB 的可用 RAM。 Even on a 32 bit system ~200 MB should not be causing a problem, and somehow the byte limit is reached.
即使在 32 位系统上,~200 MB 也不应该引起问题,并且以某种方式达到了字节限制。 What's causing the problem here?
是什么导致了这里的问题?
Using gcc 4.8.3 on Windows 8.1 with 8 GB RAM.在具有 8 GB RAM 的 Windows 8.1 上使用 gcc 4.8.3。
This seems to be a bug with GCC for c++11: Gcc uses large amounts of memory and processor power with large C++11 bitsets .这似乎是 C++11 的 GCC 的一个错误: Gcc 使用大量的内存和处理器能力与大型 C++11 位集。 Compiling with
-std=c++98
was a temporary workaround for me.用
-std=c++98
编译对我来说是一个临时的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.