Alternative fix: If you want to start indexing from 1 (like, because you have pseudocode algorithm written that way and don't want to change indexing), simplest is to allocate one bigger array and not use index 0:double *T = new double[I * J + 1];有了它,您就可以使用当前的循环.With that you can use your current loops.这种由一个数组元素造成的缓冲区溢出是令人讨厌的,因为通常在分配的内存块末尾可能有未使用的空间,因此在您更改数组大小和未使用的空间消失之前,错误可能会完全被忽视.即使溢出导致堆损坏,它也可能会被忽视,直到您更改代码和损坏的效果更改.因此,例如,如果您不走运,添加调试代码可能会隐藏问题.Such buffer overruns by one array element are nasty, because often there may be unused space at the end of allocated memory block, so bug may go totally unnoticed until you change array size and unused space disappears. And even if overrun results in heap corruption, it might go unnoticed, until you change code and effect of corruption changes. So for example adding debugging code may hide the problem if you are unlucky. 这篇关于当数组大小太大时,C++ 程序停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 16:28
查看更多