首页 > 编程语言 > 详细

C++初学者应该注意的内存错误 after Normal block。。。

时间:2014-11-15 21:33:50      阅读:298      评论:0      收藏:0      [点我收藏+]

解决 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。。。

原文:http://www.cnblogs.com/zzq-include/p/4100177.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!