KT
Size: a a a
A
АО
АО
f(x) = (x, )KT
struct Foo{T}
x :: T
end
foo = Foo([1,2,3])
m(foo) = foo.x
m2(foo) = (foo.x, 1)A
julia> mutable struct It
arr::Vector{Int64}
end
julia> function it_test(it)
push!(it.arr, length(it.arr))
return it.arr
end
julia> itt = It([])
It(Int64[])
julia> sizehint!(itt.arr, 100)
0-element Array{Int64,1}
julia> @time it_test(itt)
0.000002 seconds
KT
m не аллоцирует, а m2 аллоцируетA
АО
struct Foo{T}
arr::T
end
function process(f, x::Foo)
for i=0:1, j=0:1, k=0:1
x.arr[1] = i
x.arr[2] = j
x.arr[3] = k
f(x.arr)
end
end
foo = Foo([0, 0, 0])
process(foo) do x
println(sum(x))
endKT
collect сделать )АО
АО
VG
m не аллоцирует, а m2 аллоцируетA
A
A
@time Tuple{Int}(1)
0.000017 seconds (5 allocations: 176 bytes)julia> @time Tuple{Int}(1)
0.000000 secondsA
АО