您的位置:首页 > 移动开发

CRT detected that the application wrote to memory after after the end of heap buffer(这个经常忘掉)

2011-02-24 19:19 656 查看
在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,操作时不要越界(包括向前越或向后越).......

.....
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐