I need a minimum size implementation of an array of bools. The size of the array is known at compile time.
I checked std::bitset
and boost::array
, but they both incur an overhead that is significant for small arrays. For example, if the array size is 8, the container should only use 1 byte of memory (assuming common CPU architecture).
Does this exist or do I need to roll my own?
Boolean variables are stored as 16-bit (2-byte) numbers, but they can only be True or False.
bool The bool type takes one byte and stores a value of true (1) or false(0). The size of a bool is 1 true 1 1 1 false 0 0 0 Press any key to continue . . . int is the integer data type.
A boolean array is a numpy array with boolean (True/False) values. Such array can be obtained by applying a logical operator to another numpy array: import numpy as np a = np.
You can make it by your own, but not from scratch. bitset
implementation should have a couple of lines looking like typedef unsigned long _WordT;
(SGI) or typedef _Uint32t _Ty;
(MSVS). You could carefully replace the type and namespace and make your own container this way. I changed the type to char and sizeof
returns 1 (vs2010 proof-of-concept on pastebin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With