Here is the (very primitive) example using mpn's that I mentioned.
import Base: +
typealias ZZ Array{UInt, 1}
function +(a::ZZ, b::Int)
r = ZZ(length(a))
ccall((:__gmpn_add_1, :libgmp), Void, (Ptr{UInt}, Ptr{UInt}, Int, Int),
r, a, 3, b)
return r
end
function doit(n::Int)
a = ZZ(3)
a[1] = rand(UInt)
a[2] = rand(UInt)
a[3] = rand(UInt)
for s = 1:n
a += s
end
return a
end
This code, unlike the Julia BigInt example does not exhibit the same
behaviour. The memory usage is exactly as I would expect. It doesn't grow
at all.
Bill.