I would like to check my understanding of the inout
parameter. Assume this adt()
function is going to be called millions of times on a very very large array, lets say 10mb array. Adding the inout
parameter in this example, will prevent the 10mb array being duplicated in memory millions of times over and over again? Is that correct?
import Foundation
func adt(_ d: inout [UInt8], _ i:UInt8) {
d.append(i)
}
var d:[UInt8] = []
adt(&d,1)
adt(&d,2)
adt(&d,3)
I understand that inout
is the correct way to allow parameters outside the function to be modified, but I cant find documentation on how the memory is managed in this situation.