BitIntegers.jl icon indicating copy to clipboard operation
BitIntegers.jl copied to clipboard

No Documented way to Save Memory with BitIntegers

Open PatrickHaecker opened this issue 1 year ago • 2 comments

I get that using BitIntegers.jl is useful if you want to do residue class calculations.

However, I hoped that BitIntegers.jl could also be used to save some memory, but I haven't found that documented.

using BitIntegers, StaticArrays
@define_integers 24
SA{Int24}[1, 2, 3, 4, 5, 6, 7, 8] |> Base.summarysize

results in 40 instead of the intended 32. I understand, that the machine code accessing this array would be a bit more complicated, but that was exactly the reason why I did not want to bit-fiddle it myself.

But even the simple case of

struct Point
    a::Int24
    c::Int8
end
Point(Int24(1), Int8(2)) |> sizeof

results in 8 instead of 4.

Isn't there any way to save memory when using Int24 compared to Int32? I think either way it would help to document the behavior.

PatrickHaecker avatar Jul 31 '24 18:07 PatrickHaecker

Perhaps https://github.com/Seelengrab/FieldFlags.jl could be mentioned.

rfourquet avatar Mar 27 '25 10:03 rfourquet

It is a good idea, to mention FieldFlags.jl. I think documenting the padding issues, which are also present in C as I learned, would still be needed.

PatrickHaecker avatar Mar 27 '25 12:03 PatrickHaecker