I have a whole bunch of functions which take as their arguments slices of an array. I’d like to execute these functions with 0 allocations (if that’s even possible).
Note the following:
f(x::AbstractArray) = x + x x = rand(5) f(x) # 0 allocations f(x[1:2]) # 1 allocation f(view(x, 1:2)) # 1 allocation
In light of the above, it would seem that one option would be to pass an array and the indices to access as arguments, however this gets pretty unpleasant as I have a whole class of functions that I want to execute and they, in general, take different numbers of elements from the array. Note also that since I’m dealing with tiny slices,
view and direct indexing make similar allocations, so there’s very little advantage to using