【发布时间】:2020-09-16 00:51:23
【问题描述】:
我在 C++11 中使用无序映射,其键是各种数字和字符的串联字符串。我正在使用的密钥示例是:
coeff_key = "_"+to_string(first_k_index) +"_"+ to_string(second_k_index) +"_"+ to_string(i) +"_"+ to_string(j)+"_";
我可以填写所有地图,但是一旦我尝试访问某个密钥,就会出现问题。此外,如果first_k_index 的值可以是0-3,则不会出现错误。但是如果first_k_index 的值可以是0-9,则代码不会完全运行。这是 gdb 的输出。
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Program received signal SIGABRT, Aborted.
0x00002aaab1d2a387 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-307.el7.1.x86_64 libgcc-4.8.5-39.el7.x86_64 libstdc++-4.8.5-39.el7.x86_64
(gdb) where
#0 0x00002aaab1d2a387 in raise () from /lib64/libc.so.6
#1 0x00002aaab1d2ba78 in abort () from /lib64/libc.so.6
#2 0x00002aaab15357d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3 0x00002aaab1533746 in ?? () from /lib64/libstdc++.so.6
#4 0x00002aaab1533773 in std::terminate() () from /lib64/libstdc++.so.6
#5 0x00002aaab1533993 in __cxa_throw () from /lib64/libstdc++.so.6
#6 0x00002aaab1533f2d in operator new(unsigned long) () from /lib64/libstdc++.so.6
#7 0x00002aaab1533fc9 in operator new[](unsigned long) () from /lib64/libstdc++.so.6
#8 0x00000000004035b6 in main ()
【问题讨论】:
-
此问题显示的代码不符合 stackoverflow.com 对 minimal reproducible example 的要求。这意味着这里的任何人都不太可能最终回答这个问题。但最多只能猜测。你应该edit你的问题来展示一个最小的例子,不超过一两页代码(“最小”部分),其他人都可以剪切/粘贴、编译、运行和重现所描述的问题(“ reproducible”部分)完全如图所示(这包括任何辅助信息,例如程序的输入)。请参阅How to Ask 了解更多信息。
-
调用堆栈中有
operator new[],但标准容器使用std::allocator<T>::allocate,它只调用operator new,所以它可能在代码中的其他地方
标签: c++ unordered-map