Normally we would declare the BOOL variable:
class CMyClass {
...
BOOL m_bVar1;
BOOL m_bVar2;
BOOL m_bVar3;
BOOL m_bVar4;
BOOL m_bVar5;
BOOL m_bVar6;
BOOL m_bVar7;
BOOL m_bVar8;
...
};
Considering that the bool variable is actually an int under the Win32, which occupies 4 bytes, the above 8 bool variables will take up 32 bytes.
typedef int BOOL; BOOL takes 4 bytes
In fact, we can change the declaration of the bool variable so that it only takes up one bit:
class CMyClass {
...
BOOL m_bVar1:1;
BOOL m_bVar2:1;
BOOL m_bVar3:1;
BOOL m_bVar4:1;
BOOL m_bVar5:1;
BOOL m_bVar6:1;
BOOL m_bVar7:1;
BOOL m_bVar8:1;
...
};
In the code above, each bool variable takes up only one bit (bit), and the top 8 bool variables take up 1 bytes.
Memory savings of 32 times times!!!
However, on the other hand, the CPU in processing these bit type bool variables, the need to do bit operations to take out the value of them, so it will consume additional CPU resources. The relationship between memory and speed needs to be taken into account when using.