Opened 10 years ago
Last modified 7 years ago
#3844 assigned defect
Unnecessary array instantiations — at Initial Version
| Reported by: | Rüdiger Franke | Owned by: | somebody |
|---|---|---|---|
| Priority: | high | Milestone: | 2.0.0 |
| Component: | Frontend | Version: | |
| Keywords: | Cc: | Niklas Worschech, Francesco Casella |
Description
Examples that use constant data often result in huge code because OpenModelica instantiates these arrays over and over again. Have for instance a look the Modelica.Media.Examples.R134a.* examples.
Here is a simpler version:
package ArrayData constant Integer[:] data = {1, 2, 3, 4, 5, 6, 7, 8, 9}; function f input Integer[:] idata; input Integer idx; output Integer y; algorithm y := idata[idx] + data[idx] + data[idx + 1]; end f; model Test input Integer idx = 0; parameter Integer[:] tdata = {1, 2, 3, 4, 5, 6, 7, 8, 9}; Integer y = f(tdata, idx+1); end Test; end ArrayData;
ArrayData.Test is instantiated to:
function ArrayData.f input Integer[:] idata; input Integer idx; output Integer y; algorithm y := idata[idx] + {1, 2, 3, 4, 5, 6, 7, 8, 9}[idx] + {1, 2, 3, 4, 5, 6, 7, 8, 9}[1 + idx]; end ArrayData.f; class ArrayData.Test input Integer idx = 0; parameter Integer tdata[1] = 1; parameter Integer tdata[2] = 2; parameter Integer tdata[3] = 3; parameter Integer tdata[4] = 4; parameter Integer tdata[5] = 5; parameter Integer tdata[6] = 6; parameter Integer tdata[7] = 7; parameter Integer tdata[8] = 8; parameter Integer tdata[9] = 9; Integer y = ArrayData.f({tdata[1], tdata[2], tdata[3], tdata[4], tdata[5], tdata[6], tdata[7], tdata[8], tdata[9]}, 1 + idx); end ArrayData.Test;
It is bad if a temporary array is created when calling the function f, instead of just passing tdata. It is worse if the whole data array is created temporarily again and again whenever the function f wants to access one element of it.
Note:
See TracTickets
for help on using tickets.
