我定义了一个结构体KOVSet,其中有一个成员变量为string,我使用了Vector<KOVSet>,但在析构时报错了,我认为可能与string有关
跟string没关系,如果KOVSet里面没有指针,可以不用管,系统会自动回收。或者使用vector的clear();函数就可以了。
如果你觉得是在析构时报错是由vector引起的,那就需要考虑vector是不是在别的线程中使用了。
你最好贴出代码来才能知道到底是怎么回事。
你是如何判断是vector析构时出错的? string肯定不会有问题的。
KOVSet
struct KOVSet{
uint64_t key;
uint32_t offset;
string value;
KOVSet(uint64_t k, uint32_t o, string v){
this->key = k;
this->offset = o;
this->value = string(v);
}
};
报错的位置
1 ntdll!RtlIsZeroMemory 0x7ffe7a22f123
2 ntdll!RtlpNtSetValueKey 0x7ffe7a237ee2
3 ntdll!RtlpNtSetValueKey 0x7ffe7a2381ca
4 ntdll!RtlpNtSetValueKey 0x7ffe7a23de51
5 ntdll!RtlGetCurrentServiceSessionId 0x7ffe7a155b43
6 ntdll!RtlFreeHeap 0x7ffe7a1547b1
7 msvcrt!free 0x7ffe78ce9c9c
8 __gnu_cxx::new_allocator<KOVSet>::deallocate new_allocator.h 125 0x40e6e0
9 std::allocator_traits<std::allocator<KOVSet>>::deallocate alloc_traits.h 462 0x4126cb
10 std::_Vector_base<KOVSet, std::allocator<KOVSet>>::_M_deallocate stl_vector.h 304 0x4119a2
11 std::_Vector_base<KOVSet, std::allocator<KOVSet>>::~_Vector_base stl_vector.h 285 0x411aff
12 std::vector<KOVSet>::~vector stl_vector.h 570 0x413e31
13 SSTable::~SSTable SSTable.h 41 0x40db80
14 std::_Destroy<SSTable> stl_construct.h 98 0x41a715
15 std::_Destroy_aux<false>::__destroy<SSTable *> stl_construct.h 108 0x4117db
16 std::_Destroy<SSTable *> stl_construct.h 137 0x41a900
17 std::_Destroy<SSTable *, SSTable> stl_construct.h 206 0x41a934
18 std::vector<SSTable>::_M_erase_at_end stl_vector.h 1653 0x415232
19 std::vector<SSTable>::clear stl_vector.h 1386 0x41551f
20 KVStore::put kvstore.cc 63 0x404cae