简体   繁体   English

VS 2010是否会对malloc或新的内存分配进行检查?

[英]Does VS 2010 do bounds check on malloc or new memory allocation?

Using VS 2010. Have already analyzed for memory leakage. 使用VS 2010.已经分析了内存泄漏。 Now I want to know if during execution the compiled code is doing bounds checking. 现在我想知道在执行期间编译的代码是否正在进行边界检查。 I am reasonably certain that this happens for vectors and arrays created in C++; 我有理由相信这会发生在用C ++创建的向量和数组中; what I do not know is whether bounds checking extends to objects created either by a call to malloc or by using the new keyword. 我不知道的是边界检查是否扩展到通过调用malloc或使用new关键字创建的对象。 If VS does not do bounds checking for such a case, is there a 3rd party facility that does do it? 如果VS 不做界这样的情况下检查,是否有第三方设施,做到的?

The debug CRT heap will allocate an "overrun buffer" around the new block of memory and check the buffer for an expected value (0xFD) when the block is freed. 调试CRT堆将在新的内存块周围分配一个“溢出缓冲区”,并在释放块时检查缓冲区的预期值(0xFD)。 When the overrun buffer contains values other than what is expected, you'll get a CRT runtime check failure dialog. 当溢出缓冲区包含的值不是预期的值时,您将获得CRT运行时检查失败对话框。 This will catch overrun writes but not reads. 这将捕获溢出写入但不读取。 Unfortunately, there's no good way of catching out of bounds reads, provided your process has access to the page being read. 不幸的是,只要您的进程可以访问正在读取的页面,就没有好的方法可以捕获超出范围的读取。

See Memory Management and the Debug Heap and _CrtSetDbgFlag for more information. 有关更多信息,请参阅内存管理和调试堆以及_CrtSetDbgFlag

Arrays are not bounds checked by default in C++, regardless of whether they are statically or dynamically allocated. 默认情况下,在C ++中不对数组进行检查,无论它们是静态分配还是动态分配。 I used to use BoundsChecker for this with Visual C++. 我过去常常使用BoundsChecker和Visual C ++。 On Linux there is also valgrind, which is nice. 在Linux上也有valgrind,这很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM