Problem using System.Collections.Specialized.BitVector32: error?

I am trying to do a short simulation where I need a small bit array and I selected System.Collections.Specialized.BitVector32.

I run it inside a single-threaded object in a single-threaded loop about 1,000,000 times, each time for indices {0,1,2}.

Here is the code:

private System.Collections.Specialized.BitVector32 currentCalc 
    = new System.Collections.Specialized.BitVector32();

private void storeInCurrent(int idx, bool val)
{
    currentCalc[idx] = val;
    if (currentCalc[idx] != val)
    {
        throw new Exception("Inconceivable!");
    }
}

As far as I understand, an exception should not be thrown, but sometimes it happens! An exception is not thrown every time, but in an honest percentage - CONSTANT 1/6 of the time! (which is even stranger)

What am I doing wrong?

+3
source share
1 answer

Take a look at MSDN ; indexer takes the mask, not an index. So this is:

int mask = 1 << idx;

then use currentCalc[mask]

; - BitVector32, int. , . .

+3

Source: https://habr.com/ru/post/1717724/


All Articles