I am writing a function that stores locally a temporary set of values saved for a later computation. During “compile” time I know the size of the array. To avoid memory allocation, I am using a mutable array from the StaticArray package. See example code below that illustrates a random assignment ( in the actual code, the assignment involves a more elaborate computation).
function test1()
a=MVector{6,Float64}()
a[4]=rand()
a[1]=rand()
end
function test2()
for i in 1:10000
test1()
end
end
Timing the above results in memory allocation.
@time test2()
0.000309 seconds (10.00 k allocations: 625.156 KiB)
Is that expected? Since I know the array size at “compile time” should not there be a way to eliminate this memory cost? I am looking for an object that behaves like std::array
from c++. What is the “Julian” way?
Thanks!