传递给mex函数的数据是否保证非别名?

时间:2015-07-10 18:23:26

标签: c matlab mex

假设以这种方式调用mex函数

ret = aMexFunction(foo, foo); % same data for both inputs

在mex函数中:

void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[]) 
{
    bar(mxGetData(prhs[0]), mxGetData(prhs[1]));
}

bar定义为:

bar(Type *restrict ptr1, Type *restrict ptr2)
{         ^^^^^^^^             ^^^^^^^^   // could this be a problem?
    doSomeThing();
}

1 个答案:

答案 0 :(得分:0)

当指针不是const时,您只需要受限制的指针,因为只有在写入一个时才会出现锯齿现象。 mex函数的输入是const,并且该constness应该传递给调用函数。输入数据数组不能保证指向非混淆的存储器位置,因为MATLAB假设输入不会被改变,因为它们不应该被改变。