私は、C++を使用してインタプリタを完成しようとしています。生バージョンはうまく機能します。私はそれにメモリプールとgcを追加しようとします。メモリプールクラスMemPoolにはMemListへのポインタが格納され、MemListにはfreelistおよびbusylistへのポインタが格納されます。それらはMemBlockへのポインタであり、MemBlockにはallocateブロックのためのvoid *ポインタが含まれています。unordered_mapセグメントエラー
私はoperatortreeを上書きし、syntaxtreeノードは削除します。 operator 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は[__ CHASH] = __bucket_list _ __ndにエラーを見つけ。
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の挿入が呼び出された時点でエラーが発生していると確信しています。私は要素を挿入すると、新しいと削除が呼び出されると思います。
は、あなたがどこに間違っているとどのようにそれを
ありがとう、私はそれを試してみましょう –