ILNumerics  >  Support  >  Documentation  >  General Rules
 

General Usage Rules for ILNumerics

.NET is well known for its efficient and automatic garbage collection. However, while being sufficient for most business scenarios, mathematical applications bring more specific requirements to the memory management. Without special care, the runtime - namely the GC - would cause a serious performance hit even for middle sized problems. Therefore, ILNumerics introduces a sophisticated memory management wich saves the time in GC and therefore 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.

General Limitations

Limitations on C# language features

The following features of the C# language are not compatible with the memory management of ILNumerics and its use is not supported:

  • The C# var keyword in conjunction with any ILNumerics array types, and
  • Any compound operator, like +=, -=, /=, *= and so on.. Exactly spoken, these operators are not allowed in conjunction with the indexer on arrays. So A += 1; is allowed. A[0] += 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 explicitely defined. Just like the var keyword in C#, in Visual Basic it is not allowed to ommit array declarations:

C# Code
1
2
3
Dim A = rand(5,4,3)   ' NOT ALLOWED!                 '
 
Dim A as ILArray (Of Double) = rand(5,4,3)   ' Correct

Function Rules - Overview

In order to gain optimal execution performance, a few simple rules must be followed. These rules are described in detail in the next 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 allows for 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! ILNumerics built in functions of course are well prepared to be used with both schemes.

Function Rules