I am wondering why the second and third version allocates. What am I missing here?
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.1.0 (2019-01-21)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using StaticArrays
julia> function testthis()
function fg(x, g)
f = x[1]
return f, g
end
@allocated fg(@SVector([1.0,1.0,1.0]),@SVector([2.0,2.02,2.0]))
end
testthis (generic function with 1 method)
julia> testthis()
0
julia> testthis()
0
julia> using StaticArrays
julia> function testit()
function fg(x, g= nothing)
f = x[1]
return f, g
end
@allocated fg(@SVector([1.0,1.0,1.0]),@SVector([2.0,2.02,2.0]))
end
testit (generic function with 1 method)
julia> testit()
182676
julia> testit()
48
julia> function testnow()
function fg(x)
f = x[1]
return f, nothing
end
function fg(x, g)
f = x[1]
return f, g
end
@allocated fg(@SVector([1.0,1.0,1.0]),@SVector([2.0,2.02,2.0]))
end
testnow (generic function with 1 method)
julia> testnow()
182628
julia> testnow()
48