General Usage Rules for ILNumerics®
.NET is well known for its efficient and automatic garbage collection. This is sufficient for most business scenarios. However, when it comes to mathematical applications, the requirements in terms of memory management are more specific. Without special care, the runtime - namely the GC - would cause a serious performance hit even for middle sized problems. For this purpose, ILNumerics presents a sophisticated memory management which saves time in GC and consequently, roughly doubles the execution speed. This is archieved by:
- Value semantic for function parameters.
- After a function was left, all garbage is cleaned up immediately.
- Memory is recycled for subsequent array allocations.
- Lazy array copies - using memory on write access only.
- Array operations are done in-place, whenever possible.
Limitations on C# language features
The following features of the C# language are not compatible with the memory management of ILNumerics and their use is not supported:
- The C#
varkeyword in conjunction with any ILNumerics array type, and
- Any compound operator, like
+=, -=, /=, *=and so on. To be precise, these operators are not allowed in conjunction with the indexer on arrays. So A += 1;is allowed. A += 1;is not! If you find this rule too hard to remember, we suggest not to use compound operators at all.
Limitations on Visual Basic language features
The type for all arrays must be defined explicitely. Just like the
Function Rules - Overview
In order to achieve optimal execution performance, a few simple rules must be followed. These rules are described in detail in the Writing Algorithms Section and summerized in the following example function:
Essential Function Rules of ILNumerics: The first rule declares specific array types for input parameters and return values in function declarations. The second rule creates artificial scopes around the function body and the third rule handles assignments to output parameters.
Compatibility with older Versions
Downward compatibility was one goal which we had in mind when designing the new memory management. ILNumerics offers two usage schemes:
- all of the essential function rules are followed (recommended), or
- none of them are used.
Therefore, older algorithms work for the current ILNumerics version - abandoning the advantages of the new memory management. If in certain situations the use of all the rules cannot be guaranteed, make sure to not use any of them! Of course, ILNumerics built in functions are well prepared to be used with both schemes.