This phenomenon is found when I programmed for the LeetCode problem N-Queens.
I have two versions of accepted code, the only difference between which is the way I stored
My interpretation:
There's a vector
specialization for bool
, which is a bit map; that's highly efficient with regard to storage (1Byte of vector storage = 8 bool), but worse at actually accessing the data; for any other vector
, you can just access the element at the n
th position by *([address of first element + n * sizeof(element)])
, but for the getting bool-out-of-byte storage, you'll inevitably will need to do some bit operations, which, in times of large caches, might be significantly slower than just having an array of int
s, representing one truth value each.