Инициализация большой карты в заголовке приводит к сбою компиляции g++ ⇐ C++
-
Anonymous
Инициализация большой карты в заголовке приводит к сбою компиляции g++
I am trying to make a simple tool that requires some lookup on a fixed key-value dataset, so I try to lazily throw all data to a hashmap in the header file:
/** main.h */ #include #include using namespace std; const unordered_map test = { {0xDEADC0DE, "Some short text less than 50 characters"}, // 46K rows of data }; I haven't implemented anything yet, but just including this header file is enough to crash the compiler.
main.cpp
/** main.cpp */ #include #include "main.h" int main() { return 0; } After maxing out a CPU core for 5 minutes, the g++ (cc1plus) eats up all 32GB of RAM and crashes. I know a large header could impact compiling performance but I did not expect it to exhaust resources and fail. How does it use up 32GB RAM when the size of the header file is only 1.9 MB? Could someone please help explain the problem in my case?
The version I am using is g++ (GCC) 13.2.1 20230801, with the command /usr/bin/g++ -O3 -DNDEBUG -o CMakeFiles/main.cpp.o -c /home/foo/main.cpp
Источник: https://stackoverflow.com/questions/780 ... ation-fail
I am trying to make a simple tool that requires some lookup on a fixed key-value dataset, so I try to lazily throw all data to a hashmap in the header file:
/** main.h */ #include #include using namespace std; const unordered_map test = { {0xDEADC0DE, "Some short text less than 50 characters"}, // 46K rows of data }; I haven't implemented anything yet, but just including this header file is enough to crash the compiler.
main.cpp
/** main.cpp */ #include #include "main.h" int main() { return 0; } After maxing out a CPU core for 5 minutes, the g++ (cc1plus) eats up all 32GB of RAM and crashes. I know a large header could impact compiling performance but I did not expect it to exhaust resources and fail. How does it use up 32GB RAM when the size of the header file is only 1.9 MB? Could someone please help explain the problem in my case?
The version I am using is g++ (GCC) 13.2.1 20230801, with the command /usr/bin/g++ -O3 -DNDEBUG -o CMakeFiles/main.cpp.o -c /home/foo/main.cpp
Источник: https://stackoverflow.com/questions/780 ... ation-fail
Мобильная версия