2
假设一个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();
}
详细说明在这些论点中发生的情况吧? – this
@this bar采用'restrict'ed指针,所以如果'mxGetData(prhs [0])'和'mxGetData(prhs [0])'返回相同的底层存储位置,则它是UB。 – user3528438
@Praetorian http://undocumentedmatlab.com/blog/matlab-mex-in-place-editing根据这个链接,Matlab在传递给mex函数时不会重复数据。而不是只写别名的“限制”指针,从别名“限制”指针读取也会导致不好的结果。 – user3528438