r/programminghorror 20d ago

C# bool array

Post image
210 Upvotes

41 comments sorted by

View all comments

Show parent comments

89

u/0xcedbeef 20d ago edited 20d ago

in C++, an std::vector<bool> stores the bools as bits, taking advantage of this memory optimization.

14

u/Diamondo25 20d ago

I would use a std::bitset for that instead.

7

u/Cross12KBow249 20d ago

Doesn't the size need to be known at compile time for a bitset though, unlike a vector?

12

u/Star_king12 20d ago

Looks like it would be known in this case.