To allocate a double
array initialized to zero, you can choose
var x = new double[N];
to allocate on the heap and
Span<double> x = stackalloc double[N];
to allocate on the stack.
To suppress initialization to zero, you can call
var x = GC.AllocateUninitializedArray<double>(N);
to allocate on the heap, but I don't know how to do the same thing on the stack. You can use the SkipLocalsInit
property, but that then requires compiling in unsafe. Is there a way to achieve this result but not use unsafe?