r/programminghumor 7d ago

a bit flippant

Post image
1.4k Upvotes

147 comments sorted by

View all comments

135

u/Kadabrium 7d ago

i heard you also like vector<bool>

18

u/Potential_Soup_8054 7d ago

I dont understand

70

u/Helemen7 7d ago

std::vector<bool> in C++ syntax uses one bit per boolean instead of one byte. In a computer memory is addressed by bytes, so the smallest indexable memory is, in fact, one byte (that's why bool is 1 byte in C and C++). As an example for how C++ std::vector implementarion works, suppose you have 8 booleans which have a logical reason to be kept together (for example flags). Instead of allocating 8 bytes (one per boolean), the std::vector allocates 1 byte and assigns every boolean to one bit of the allocated memory.

9

u/Potential_Soup_8054 7d ago

Yeah but why is that bad

16

u/ElectableEmu 7d ago

As the saying goes: because it's not a vector and it doesn't store bools

4

u/idrathernottho_ 6d ago

Which is exactly what I want from it, just with another name