Unnecessary copying in Matlab Coder generated C code

2 ビュー (過去 30 日間)
Jane Jean
Jane Jean 2013 年 8 月 1 日
Hi! I generated C code with Matlab Coder can I realize that there are a lot of such unnecessary copying. What can I do to avoid that?
for (i0 = 0; i0 < 153; i0++) {
dv42[i0] = dv74[i0];
dv43[i0] = dv75[i0];
}
...
for (i0 = 0; i0 < 153; i0++) {
dv74[i0] = dv42[i0];
dv75[i0] = dv43[i0];
}
...
for (i0 = 0; i0 < 153; i0++) {
dv42[i0] = dv74[i0];
dv43[i0] = dv75[i0];
}
  1 件のコメント
Ryan Livingston
Ryan Livingston 2013 年 8 月 1 日
編集済み: Ryan Livingston 2013 年 8 月 1 日
If you post a small example of MATLAB code which produces this, we may be able to give some suggestions.

サインインしてコメントする。

回答 (1 件)

Jane Jean
Jane Jean 2013 年 8 月 1 日
I have a structure in Matlab similar to what is below and right before the subfunction is called, the generated C code is doing the unnecessary copying instead of taking 'a' directly as an input of the subfunction.
function output = main_function(a)
...
a = [1;2;3];
...
output_sub = subfunction(a)
  2 件のコメント
Walter Roberson
Walter Roberson 2013 年 8 月 1 日
The copying would be appropriate if the subfunction modifies its input, which we cannot determine from what you show.
Why are you passing "a" into main_function and also assigning a value to it?
Jane Jean
Jane Jean 2013 年 8 月 1 日
'a' is first used somewhere before it is reassigned with another value. But right before it is fed into 'subfunction', 'a' is copied to another temporary variable, e.g. 'dv74' then the latter is copied to 'dv42' and 'dv42' is copied back to 'dv74' and 'dv74' is again copied to 'dv42' and finally subfunction takes 'dv42' as input. What can I do to avoid this unnecessary copying?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by