Avoid Copies of Large Arrays doesn't work (c++)
이전 댓글 표시
Hi,
I'm trying to write a simple function to verify that my c++ code won't copy large arrays, like in this example:
I wrote the following function:
#include "mex.hpp"
#include "mexAdapter.hpp"
class MexFunction : public matlab::mex::Function {
public:
void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
matlab::data::TypedArray<double> x = std::move(inputs[0]);
x[0] = 2;
outputs[0] = x;
}
};
It seems to run very slow, so I'm guessing it is because of data being copied.
>> x = rand(1e8,1);
>> tic; x = example(x) ; toc;
Elapsed time is 0.664293 seconds.
>> tic; x(1) = 2 ; toc;
Elapsed time is 0.000065 seconds.
Any ideas?
Thanks!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Use Prebuilt MATLAB Interface to C/C++ Library에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!