Reputation: 8991
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
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
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
Reputation: 476950
bool[N]
will occupy N times sizeof(bool)
contiguous bytes in memory.
Upvotes: 7