calccrypto
calccrypto

Reputation: 8991

Bool array problems in c++

Is an array of bools also "optimized", like a vector<bool> is? I want to make arrays of true or false, but I also dont want the problems that some with vector<bool> to show up in an array, such as slow access times

Upvotes: 2

Views: 2582

Answers (3)

Jack
Jack

Reputation: 715

I think the C++ default implementation is mainly for saving the space, while the access time may be affected.

if you need quicker access time, you may have implement it by yourself and sacrifice the space.

Upvotes: 1

Steve C
Steve C

Reputation: 647

Optimized for speed is one bool per word so it doesn't need to do masking and read-modify-write operations. Optimized for space would be to pack 32 bools per word, so you have to be more specific about what "optimized" means.

Upvotes: 3

Kerrek SB
Kerrek SB

Reputation: 476950

bool[N] will occupy N times sizeof(bool) contiguous bytes in memory.

Upvotes: 7

Related Questions