Packed Structure Size Bools

If 1 bool is 1 byte [8 bits], will the 4-point packed structure be 32 bits or 4? The pack directive removes the alignment requirement, but will it make [buse] memory more efficient?

+5
source share
4 answers

Yes. Even a packed boolean structure will use at least 8 bits in a boolean. If you do not use bit fields .

+5
source

4 bools.

Everyone boolneeds a unique address (since you can accept the address bool). If you use a field bit, you can reduce the size to 1 bool, but you cannot get the address of a single bit field.

+1

bool . , , int (, , ). sizeof (bool) 1, bools 4 ( , 32 )

, , :

std::vector<bool>

: http://www.cplusplus.com/reference/stl/vector/

( ) , . , , .

FD_SET.

+1

. .

:

5.3.3

sizeof . , , . sizeof , , l, -. sizeof (char), sizeof ( char) sizeof ( char) 1; sizeof, (3.9.1), . [: - , sizeof (bool) sizeof (wchar_t) .69)] [: . 1.7 3.9 . ]

0

All Articles