在Windows上堆损坏,而不是Linux上的堆损坏

Heap corruption on Windows but not Linux

本文关键字:损坏 Linux Windows      更新时间:2023-10-16

下面是一些简单的OpenCV代码,用于从视频文件创建帧并在帧上运行SURF特征检测器和提取器。当我在 Linux 和 OSX 上运行此代码时,它运行良好,但是在 Windows 上,我在两个注释行上收到堆损坏错误。

VideoCapture capture(vidFilename.c_str());
Mat frame;
capture >> frame; 
SurfFeatureDetector *detector = new SurfFeatureDetector(minHessian);
vector<KeyPoint> frameKeypoints;
detector->detect(frame, frameKeypoints);
delete(detector); // Heap Corruption Detected
SurfDescriptorExtractor *extractor = new SurfDescriptorExtractor();
Mat frameDescriptors;
extractor->compute(frame, frameKeypoints, frameDescriptors);
delete(extractor); // Heap Corruption Detected

我不知道代码中可能导致这种情况的原因是什么。我正在使用VS 2010来编译代码,VS中是否有可能导致这种情况发生?

如上所述,您不会获得与堆损坏相关的任何异常并不意味着它没有发生。您的代码中会有问题,而不是在 VS 或编译器中。我之前关于类似文章的文章在这里也很有用。

https://stackoverflow.com/a/22074401/2724703

可能你也应该尝试在你的Linux上运行一些动态工具(Valgrind)。很有可能,你也会在使用Valgrind发现同样的错误。

这些动态工具将为您提供这些问题的根本原因。