Info

此问题已关闭。 请重新打开它进行编辑或回答。

Prevent codegen from creating matrix copy for use as const* function parameter

1 次查看(过去 30 天)
Using MATLAB R2018a with MEX code generation I have some troubling preventing from creating unnecessary copies of a value class present in the MATLAB code to be converted into C code.
The code pattern is as follows:
output = cell(P,1)
hugeblockoflogical = false(M,N)
% Fill all of output{:}
for i = 1:P
(code that reads/writes to/from hugeblockoflogical)
% ???
hugeblockoflogical_copy = initheap(hugeblockoflogical)
% Create class from matrix and store in output argument
% ValueClass constructor does NOT modify input argument
output{i} = ValueClass(hugeblockoflogical_copy)
end
At the assignment of output{i} Codegen decides to create a full copy of hugeblockoflogical before passing that copy into the constructor of ValueClass as a const pointer.
From inspecting the generated C code I see no reason why the huge copy should be generated.
Anyone have a suggestion as to why this is happening and how to prevent it?

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by