Arbitrary Size Integer Arrays

dsimcha dsimcha at yahoo.com
Mon Sep 21 13:26:28 PDT 2009


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> dsimcha wrote:
> > 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?
> I think that would be a nice addition. We haven't established some
> general rules for containers. Values or references? In the latter case:
> Classes or structs? If classes: hierarchy or largely independent classes?
> Andrei

I'd go with struct value type to make it as similar feeling to a regular array as
possible. On the other hand, regular arrays are going to be overhauled anyhow, so
that makes me not so sure.



More information about the Digitalmars-d mailing list