Arbitrary Size Integer Arrays
dsimcha
dsimcha at yahoo.com
Mon Sep 21 12:11:59 PDT 2009
I'm thinking it might be useful to have a library type that allows for
arbitrary size integers <= 64 bits (128 if ucent is ever implemented) to be
packed into an array. This might be nice when you want a huge array of them,
the size you actually need is somewhere in between two native sizes, and you
care more about space/cache efficiency than raw CPU cycles. For example,
let's say you wanted an array of N 19-bit integers. You'd make an array of
uints (32-bit) with ceil(N * 19 / 32) elements, and when it was indexed, you'd
do a bunch of modulus and bit shifting to get the right 19 bits out of that
block of memory, and return a uint. It would be slow as molasses, but really
space efficient, which would in certain cases be a reasonable tradeoff.
Has anyone implemented, or considered implementing this before? If not, if I
implemented it well and submitted it as an enhancement, would it be a
reasonable thing to include in std.array?
More information about the Digitalmars-d
mailing list