1

I would like to allocate an array in ILNumerics C# that isn't initialized to any values. I know I am going to write over every entry in the array so it doesn't need to be initialized. This will help with a computationally intensive task.

Do I need to dive into ILMemoryPool in order to do this? It would be nice to have a standard array constructor that provided this capability and I haven't been able to find it.

Thanks, Eric

1 Answers1

0

You are right, the memory must come from the memory pool. But there is a wrapper 'ILMath.New(int)' which somehow eases the access:

double[] mem = ILMath.New<double>(1000000);
ILArray<double> A = ILMath.array(mem, ILMath.size(1000,1000)); 

Keep in mind, if you are using the memory inside an ILArray<T> you dont need to keep track of it manually. It is freed automatically and returned to the pool once the ILArray runs out of scope.

Conversely, if you need the System.Array for other direct computations, the ILNumerics memory management cannot help and you need to manually give the memory back to the pool afterwards:

ILMath.free(mem);  
Haymo Kutschbach
  • 3,322
  • 1
  • 17
  • 25
  • C# doesn't have C++-like destructors, so how could the ILArray memory be returned to the pool "once the ILArray goes out of scope"? That's not even something that can be safely implemented with a finalizer. – Trillian Mar 06 '14 at 02:59
  • The ILNumerics memory management keeps track of it. It realizes a deterministic disposal by sticking to 3 simple rules: http://ilnumerics.net/FunctionRules.html – Haymo Kutschbach Mar 06 '14 at 12:47
  • So it's based on `IDisposable`/`using` statements, not arbitrary lexical scopes. – Trillian Mar 06 '14 at 13:30