Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

5 Ansichten (letzte 30 Tage)
JM
JM am 18 Mär. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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?

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by