﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
6220	Small array optimizations: stack allocation	Mahder Alemseged Gebremedhin	Mahder Alemseged Gebremedhin	"Arrays of OpenModelica runtime are defined as the following struct

{{{#!c
struct {
  int ndims;
  _index_t *dim_size;
  void* data;
  m_boolean flexible;
};
}}}

Here is a very basic ""small static"" array of 1 dimension that can be a starting point for implementation.

{{{#!c
#define SMALL_ARRAY_1(name, type, dim1) \
      struct { \
        int ndims; \
        _index_t *dim_size; \
        void* data; \
        m_boolean flexible; \
        _index_t dim_size_d[1]; \
        type data_d[dim1]; \
      } name = {1, arr1.dim_size_d, arr1.data_d, 0, {dim1}, {0}};
}}}

It can be used as 
{{{
SMALL_ARRAY_1(arr1, modelica_real, 3);
}}}

to declare an `arr1` array of `modelica_real` with 1 dimension of size 3.  


This matches the expected interface for normal (non-static) arrays while keeping its data on stack. That is, it can be passed to functions that we already use for the normal arrays. Of course there are warning about incompatibility of passed pointers and so on. For example this can be passed to ""getter"" functions as

{{{#!c
real_array_get(arr1, 1, _i) = 1;
}}}

We need to figure out a way to safely copy these and normal arrays between each other (if that turns out to be needed).

There are many things that can go wrong with this. We will find out.

If you have suggestions, ideas, tricks, concerns ... please let me know :). We want to implement this with as small change as possible to code generation and Modelica compilation. "	defect	new	normal	NeedsInput	Run-time				Francesco Casella
