开发者

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 don开发者_开发知识库t 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜