在VS2005写完程序后,运行后弹出对话框显示:

HEAP CORRUPTION DETECTED:

CRT detected that the application wrote to memory after after the end of heap buffer

最后定位到代码

ans = new int[size_a+size_b];        // 动态分配数组空间

delete [] ans;

一把delete [] ans;删掉程序就不弹出错误,这是为什么呢??

错误原因

因为对内存的操作越界了,超出所分配的内存的边界。

解决:

增大分配的内存!   

e.g.

ans = new int[size_a+size_b +1 ];     

或者加到自己适宜的大小,问题即可解决...

总结:

对内存的操作要细之又细,new完后要delete,操作时不要越界(包括向前越或向后越).......

.....


相关文章:

  • 2021-05-04
  • 2021-05-20
  • 2021-08-13
  • 2021-07-26
  • 2021-12-21
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案