码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-11-15 21:36:53      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   on   问题   bs   amp   new   c++   

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

标签:io   ar   sp   on   问题   bs   amp   new   c++   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!