g++ 4.8.1 on Ubuntu can't compile large bitsets

柔情痞子 提交于 2019-12-05 20:08:37

On my machine, g++ 4.8.1 needs a maximum of about 17 gigabytes of RAM to compile this file, as observed with top.

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
18287 nm        20   0 17.880g 0.014t    808 D  16.6 95.7   0:17.72 cc1plus

't' in the RES column stands for terabytes ;)

The time taken is

real    1m25.283s
user    0m31.279s
sys     0m5.819s

In the C++03 mode, g++ compiles the same file using just a few megabytes. The time taken is

real    0m0.107s
user    0m0.074s
sys     0m0.011s

I would say this is definitely a bug. A workaround is to give the machine more RAM, or enable swap. Or use clang++.

[Comment]

This little thing:

#include <bitset>
int main() {
    std::bitset<8000000000UL> b;
}

results in 'virtual memory exhausted: Cannot allocate memory' when compiled with g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!