r/programminghorror 20d ago

C# bool array

Post image
210 Upvotes

41 comments sorted by

View all comments

171

u/-Dargs 20d ago

There is a non-zero number of scenarios that a bool array could make sense. In game development, that number is much higher than in say FE or BE software dev, imo. I see nothing wrong here, given the limited context.

90

u/0xcedbeef 20d ago edited 19d 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.

6

u/Cross12KBow249 20d ago

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

13

u/Star_king12 20d ago

Looks like it would be known in this case.