Bitarray size limits

bearophile bearophileHUGS at lycos.com
Wed Apr 25 09:33:35 PDT 2012


ixid:
> These seem to be limited to uint.max length. Is there a way to 
> make larger bit arrays?

Yeah, fixing the BigArray source :-)

It's limited by size_t.max length, that equals to uint.max on 32 
bit systems.

It contains code like:

struct BitArray {
     size_t len;
     size_t* ptr;

     @property const size_t dim() {
         return (len + (bitsPerSizeT-1)) / bitsPerSizeT;
     }
     @property const size_t length() {
         return len;
     }
...
}


To create larger arrays that 'len' needs to be a ulong. So it 
needs to become something like this:

struct BitArray(bool hugeToo=false) {
     static if (hugeToo) {
         alias ulong Tindex;
     else
         alias size_t Tindex;
     Tindex len;
     size_t* ptr;

     @property const Tindex dim() {
         return (len + (bitsPerSizeT - 1)) / bitsPerSizeT;
     }
     @property const Tindex length() {
         return len;
     }
...
}


But this may cause some problems because BitArray is trying to 
look like a dynamic array, while now it's something that can be 
longer (and with a larger struct) than any dynamic array, so 
_from the outside too_ the management of its length needs extra 
care.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list