Let's say I have a struct using bit-fields like that :
struct SomeData
{
char someChar:5;
char someSmallerChar:3;
}
The size of the content of one SomeData
should be one char long instead of two, thanks to bitfields.
Now if I want to organize my data this way...
class SomeDataContainer
{
std::vector<char> someChar;
std::vector<char> someSmallerChar;
}
... I lose the benefit I had with the bit-fields regarding space efficiency. The size of the equivalent container is now twice the original one.
Is there a way to create a vector of char:5
and char:3
or something similar to it to get the same benefits while having the data in this vector format (contiguous in memory) ?