I have this code:
let timer = new System.Diagnostics.Stopwatch()
timer.Start()
Array.zeroCreate<int> 100000000
timer.Stop()
printfn "%ims" timer.ElapsedMilliseconds
timer.Reset()
timer.Start()
Array.create 100000000 0
timer.Stop()
printfn "%ims" timer.ElapsedMilliseconds
I tested it and had these results:
0ms
200ms
How does Array.zeroCreate
create array so fast and it's guaranteed that all it's elements have default value? In other languages I know there are no such possibilities (as far as I know). In other languages I know only about fast initialization of array which elements are not guaranteed to have default value, because they can be initialized in memory where some garbage lies.
Thanks!