tgu
(Thomas)
November 22, 2025, 9:19am
1
Hi,
I was playing around with InlineArray and found out that this function
func col(i: Int, v: InlineArray<8, InlineArray<10, Int>>) -> InlineArray<10, Int> {
[v[i][0], v[i][1], v[i][2], v[i][3], v[i][4],
v[i][5], v[i][6], v[i][7], v[i][8], v[i][9]]
}
puts 10 copies of v on the stack. godbolt . Am I missing something?
2 Likes
ibex
November 22, 2025, 9:58am
2
Is the input array an array of 8 rows or 8 columns?
It looks like it is an array of 8 columns, judging by the return value of the function. Then, the return value should be just the i th element of the input array. No?
tgu
(Thomas)
November 22, 2025, 10:27am
3
Yes, in this simplified example, you could do this
func row(i: Int) -> InlineArray<10, Double> {
return vec[i]
}
And that function will still create one unneccessary copy of vec.
nixberg
November 22, 2025, 11:12am
4
Similar problem. Local (or struct property, or global) array results in a lot of moves; output is fine when the array is a static property.