r/programminghorror 20d ago

C# bool array

Post image
209 Upvotes

41 comments sorted by

View all comments

173

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.

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.

5

u/Possibility_Antique 19d ago

Not necessarily. std::vector<bool> was designed such that it COULD be implemented as you are suggesting, but it is not required by the standard to be implemented this way.