Int -> Str -> print(io,_) without allocations

Leo_I
Thu, 18 Dec 2025 08:49:13 +0000
General Usage

I have billions of Ints that I wish to write to a file. Something similar to mmwrite() in MatrixMarket.jl. I am already using IOBuffer with a large enough sizehint. When I do print(io, n::Int), behind the scenes, a conversion to String is made, causing lots of allocations, slowing down the process.

Strings are variable-sized, hence allocate. Is there a more efficient way to do s=some_efficient_string_type(n); print(io,s) that would avoid allocations? Perhaps something related to ShortStrings.jl or StaticStrings.jl?

Related: print(iobuffer, number) without calling string(number)? · Issue #55835 · JuliaLang/julia · GitHub

17 posts - 8 participants