Инициализация большой карты в заголовке приводит к сбою компиляции g++C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Инициализация большой карты в заголовке приводит к сбою компиляции g++

Сообщение Anonymous »


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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»