简体   繁体   中英

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM