unordered_map segment fault
unordered_map segment fault
我正在尝试使用c ++完成一个intepreter。原始版本效果很好。我尝试向其添加内存池和gc。内存池类 MemPool 包含指向 MemList 的指针,MemList 包含指向自由列表和忙列表的指针。它们是指向 MemBlock 的指针,MemBlock 包含一个用于分配块的 void * 指针。
我覆盖运算符 new 并删除语法树节点。运算符 new 仅用于 ASTree 基类,malloc 在其他情况下用作替代项。ASTree 是所有语法树节点的基类。
void *ASTree::operator new(size_t size){
cout<<"Using modified new operator!"<<endl;
void *buff=MemPool::getInstance()->alloc(size);
return buff;
}
void ASTree::operator delete(void *buff){
if(!MemPool::getInstance()->dealloc(buff))
throw MemoryError(curmodname,curline);
}
在声明节点中,我使用 unordered_map 来存储相关的子声明。
class DeclModule:public Declaration{
public:
DeclModule(const string &modname);
// ~DeclModule();
int getDeclType();
void intepret();
string modname;
unordered_map<string, DeclModule *> modulelist;
unordered_map<string, DeclClass *> classlist;
unordered_map<string, DeclMethod *> methodlist;
DeclEntry *entry;
};
我发现程序在不同时间在不同的地方崩溃。我发现错误可能是由unordered_map引起的
DeclMethod *declmethod=methodParser();
declmodule->methodlist[declmethod->methodname]=declmethod;
有时 xcode 在 __nd = __bucket_list_[__chash] 中定位错误;
template <class _Key, class _Args>
_LIBCPP_INLINE_VISIBILITY
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
#endif
{
size_t __hash = hash_function()(__k);
size_type __bc = bucket_count();
bool __inserted = false;
__next_pointer __nd;
size_t __chash;
if (__bc != 0)
{
__chash = __constrain_hash(__hash, __bc);
__nd = __bucket_list_[__chash];
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
__constrain_hash(__nd->__hash(), __bc) == __chash;
__nd = __nd->__next_)
{
if (key_eq()(__nd->__upcast()->__value_, __k))
goto __done;
}
}
}
有时定位错误
__builtin_operator_delete(__ptr);
有时 xcode 告诉我我不能使用释放(指针或内存?记不清楚(。我确定在调用插入时会发生错误unodered_map。我想当我插入一个元素时,新的和删除被调用的。五月
需要你的帮助T-T,你能告诉我哪里有问题以及如何修改它吗
如果没有实际调试,很难回答这个问题,但我认为您的池分配器中存在错误。
我建议你运行像valgrind这样的调试工具,而不是解决方案,如下所示:在Xcode环境中,Valgrind相当于什么?
否则,如果你的代码在Linux上独立编译,你可以直接使用valgrind。
如果应用程序是多线程的,请确保池分配器是安全的。
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 给定一个整数数组,需要在Max_Heap上运行操作。得到错误"segmentation fault",有什么想法吗?(C++)
- 循环时无法进入:"Segmentation fault"
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- OpenGL "Segmentation fault"错误
- 如何修复访问动态数组中结构中的字符串变量时"segmentation fault (core dumped)"错误
- 如何修复 C++ 中的'Segmentation fault'错误
- unordered_map segment fault
- 创建一个简单的类及其变量和函数不断返回" segmentation fault (core dumped)"、C++
- 在 Mac OS 上遇到的"Segmentation fault: 11" [C++]
- Getter seg fault
- 在 Linux 上实施英特尔 MKL 的 DFT 时"Segmentation fault"
- 尝试读取包含 ints 并存储在 int vector 中的文件,但我不断收到错误"Segmentation fault (core dumped)"
- 在非空 std::list 上使用 std::list.back<int>() 时"Segmentation Fault"
- 我正在尝试通过说话传递一些字符串,它会读取它们,但我得到了"segmentation fault"
- 为什么当我更改此代码时会给我"segmentation fault"错误?
- C++ cin , Segment fault 11
- std::map< MyClass, std::vector<MyClass> > Segment fault。奇怪