首页 > 代码库 > C++初学者应该注意的内存错误 after Normal block。。。
C++初学者应该注意的内存错误 after Normal block。。。
解决 after Normal block(#908) at 0x399EC0. CRT detected that the application wrote to memory after end of heap buffer 内存出错
1. 数组越界所导致
char* pBuffer = new char[2];
int v = 123;
strcpy(pBuffer, &v);
delete[] pBuffer;
2. 释放过的内存没有置为0,也就是就是野指针的问题
if (this->mstr != NULL)
{
delete[] this->mstr;
}
this->mstr = NULL;//必要
3.初学者在申请内存的时候”大意了“
char* pBuffer = new char[strlen(this->p)+1];
却写成了
char* pBuffer = new char(strlen(this->p)+1);
同样会在 析构delete[]的时候出现 内存中断。
C++初学者应该注意的内存错误 after Normal block。。。
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。