-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Currently all requested values are copied twice for every call of fmi3GetX / fmi3SetX which is inefficient in terms of bandwidth and memory usage. This can be avoided by re-using the memory for subsequent calls of the getters and setters.
A possible implementation is outlined below. (It is the result of a discussion with @pmai)
Instantiation
The FMU allocates the memory for all variables during fmi3Instantiate using the callbacks provided by the environment.
For FMUs that don't support variable array sizes this memory may be static. The FMU may even use this memory directly for it's calculations.
The Memory layout is defined by the model description: it is the same as for a get / set call where all variables of a respective type are set / retrieved in the same order as they appear in the model description.
Get variables
fmi3Status fmi3GetX(const fmi3ValueReference vr[], size_t nvr, fmi3X* values[], size_t *nValues);
vr: all variables the caller is interested in (NULL = all)nvr: size of vrvalues: the memory that contains the variablesnValues: size ofvalues
Set variables
fmi3Status fmi3SetX(const fmi3ValueReference vr[], size_t nvr, fmi3X values[], size_t nValues);
vr: all variables that have changed since the last call to fmi3SetX (NULL = all)nvr: size of vrvalues: memory retrieved fromfmi3GetXnValues: size ofvalues
The value references are provided to allow optimizations if only a small number of variables are set / retrieved.
Structural changes
The FMU re-allocates the memory using the callbacks provided by the environment. The memory layout changes according to the structural parameters.
Termination
In fmi3Terminate() the FMU frees the memory using fmi3Free()
Comments welcome!