【问题标题】:Access violation occurs using tbb::allocator<T>.allocate使用 tbb::allocator<T>.allocate 发生访问冲突
【发布时间】:2013-06-22 10:29:24
【问题描述】:

我正在尝试使用 TBB 来提高使用 OpenCV 的计算机视觉项目的性能。这是代码中给出访问冲突的部分。

#include <opencv/cv.h>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "tbb/pipeline.h"
#include "tbb/tick_count.h"
#include "tbb/task_scheduler_init.h"
#include "tbb/tbb_allocator.h"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
    string file = "myimage.jpg";
    Mat* mats2=tbb::tbb_allocator<Mat>().allocate(100);
    for (int i = 0 ; i < 100 ; ++i)
    {
        mats2[i]=imread(file);         <===== Access Violation
        imshow("temp",mats3[i]);
        waitKey(1);
    }
}

为什么这是访问冲突? Mats2 不是 0 并且肯定分配给内存中的一个地址。我知道这个link 中可以使用的其他函数,但我想知道导致这个错误的 tbb_allocator 中发生了什么。如果与 malloc 或可扩展的_malloc 一起使用,代码不会出错。

【问题讨论】:

  • 考虑设置c++标签。

标签: c++ multithreading opencv tbb


【解决方案1】:

看起来,这是一个 C-C++ 问题。 New 和 Delete 有效,但仍可扩展的分配会导致访问冲突。听起来像是目前 OpenCV 用户的唯一选择。

【讨论】:

    【解决方案2】:

    我不知道这是否有帮助

    imread(filename)

    只是尝试从文件内容推断文件的格式。 只需检查您需要如何使用此调用即可。

    【讨论】:

    • 我几乎不相信是这样的。 imread 读取图像并将其存储在 Mat 容器中。如果是这种情况,它也不应该与 malloc 一起使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多