Thread overview
Bitarray size limits
Apr 25, 2012
ixid
Apr 25, 2012
bearophile
Apr 26, 2012
ixid
April 25, 2012
These seem to be limited to uint.max length. Is there a way to make larger bit arrays?
April 25, 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
April 26, 2012
Thank you, I will have a play with that.