Memory utilization

Depending on how the IQANdesign application is built, there can be significant differences between memory and cycle utilization for the exact same functionality. 

This knowledge base article looks at a few minimal examples to illustrate differences in memory utilization. 

Utilization example A

Consider a function that: 

  • checks that two sensor values are below a fixed threshold 
  • has an override that can activate the function even if the condition for the sensors aren't met

This is a relatively inefficient Qcode implementation: 

overrideVariable := Override
sensorA_Low := SensorA < 50
sensorB_Low := SensorB < 50

if (SensorA_Low and sensorB_Low) or overrideVariable then Result:=True

It does however have the advantage that when measuring, each condition has a line of its own: 

Image 1882

For a slightly more efficient implementation, the if-statement can be omitted, assigning Result directly. 

 

overrideVariable := Override
sensorA_Low := SensorA < 50
sensorB_Low := SensorB < 50

Result:= (SensorA_Low and sensorB_Low) or overrideVariable

A more efficient Qcode expression can be achieved by omitting the variables that hold intermediate results:  

Result:= (SensorA < 50 and SensorB < 50) or Override

Image 1883

A drawback of this single line is that it can be harder to see the individual conditions. Here a classic object list can help. 

Image 1884

The difference in RAM memory utilization can be seen i the project statistics. 

Estimate calculated in IQANdesign 7.01:

Image 4137

Utilization example B

Consider a function that:

  • checks that a sensor value (e.g. speed) is close to zero
  • at the same time checks the sensor status, to handle the event that the value zero might be due to a sensor fault

A relatively inefficient Qcode implementation could look like this:

//check that movement is stopped
speedIsLow := Speed < 1
speedSensorOK := StatusOf(Speed) = stOK

if speedIsLow and speedSensorOK then
Result := True
else
Result := False
endif

That can easily be simplified to:

//check that movement is stopped
speedIsLow := Speed < 1
speedSensorOK := StatusOf(Speed) = stOK

Result := speedIsLow and speedSensorOK

A more compact implementation that saves memory would be: 

//check that movement is stopped
Result := Speed < 1 and StatusOf(Speed) = stOK 

In this example, an object list would be the most efficient: 

Image 1886

The difference in RAM memory utilization can be seen i the project statistics.

Estimate calculated in IQANdesign 7.01:

Image 4138


To explore these examples, see attached example file:

Memory utilization.idsx



The system information channel for MC4x will show the actual total memory utilization. 

Note that these examples are put in individual function groups for easy comparison in project statistics. Channel scope protected is used to eliminate the impact of FGI channels, but each FG:s in itself also contributes to the utilization seen here. 


The article has been updated to show memory utilization in 7.01, a reduction compared to the attached 5.06 project file. Optimizations in future versions may further improve RAM utilization. 

This article was helpful for 5 people. Is this article helpful for you?