ILNumerics - Technical Computing Tools

High Performance Framework for Visualization

and Computing in Industry and Science



Optimizing Performance

All methods described on this page are optional. Usually, the userdoes not need to deal with them. However, in certain edge cases, they can be of good help, in order to minimize resource usage to the most possible extent.


Limiting Memory Usage

While 'using' blocks are obligatory at least around the function body, there might be situations, where this is not enough. Long running 'for', 'foreach' and 'while' loops are typical cases of an exhausted memory consumption. Consider the following example:

In this case, the loop body should be enclosed by another using block. This ensures that every single iteration of the loop does not use more memory than really needed:

The scope created by the 'using' block ensures that all memory is immediately reclaimed as soon as the scope is left. Memory for local arrays, declared / assigned during the execution of the function is accumulated in this manner and disposed once the scope is left.

But there even exists an easy way to dispose all memory immediately during the run of the function: only assign arrays to local variables by using the .a setter property, as known from the output parameters:

However, the code obviously becomes more clumsy and precautions have to be taken, in order to prevent NullReferenceExceptions. Therefore, these options are left to situations with the highest performance requirements.