读后: C++指针数组:delete还是delete[]? (由 shai vashid 回复)和 http://www.cplusplus.com/forum/beginner/6651/
我实现了以下内容:
内核.h
unsigned int **ConfigMeM;
//.....
~Kernel(){ //destructor
for (unsigned int i=0; i<MeMSize; i++)
delete [] MeM[i]; //Valgrind:- Invalid read of size 4
- Invalid free() / delete / delete[] / realloc()
delete [] MeM; //Valgrind: Invalid free() / delete / delete[] / realloc()
for (unsigned int i=0; i<_item_tot; i++)
delete [] ConfigMeM[i]; //Valgrind: Same comments as above
delete [] ConfigMeM; //Valgrind: same as above
};
内核.cpp
//.......
MeM = new unsigned int*[MeMSize];
for (unsigned int i=0; i<MeMSize; i++){
MeM[i] = new unsigned int[11]; //Valgrind: 14,608 bytes in 332 blocks are definitely lost in loss record 2,021 of 2,036
}
for (unsigned int i=0; i<MeMSize; i++){
for (int j=0; j<10; j++){
MeM[i][j] = 0;
}
}
//.....
ConfigMeM = new unsigned int*[_item_tot];
for (unsigned int i=0; i<_item_tot; i++){
ConfigMeM[i] = new unsigned int[3]; //Valgrind: 1,200 bytes in 100 blocks are definitely lost in loss record 1,131 of 2,036
}
for (unsigned int i=0; i<_item_tot; i++){
for (int j=0; j<3; j++){
ConfigMeM[i][j] = 0;
}
}
//.....
我不确定我做错了什么。
请问有什么建议吗?
谢谢你。