would assume that a primitive boolean would only take 1 bit of storage, but it seems it takes 8 bits (according to Oracle JVM doc)
Moreover, the Oracle tutorial says that the size is not precisely defined. I understand that other JVM implementations may have different implementation for booleans, but why? This makes it so much more confusing
It is impossible to fetch a singke bit from memory, most assembly languages do not support that. To store a boolean as a single bit would come with much memory management effort. Such ways of data access exist, for example in C++ with std::vector<bool>, but are not suitable for a general use data type as a primitive boolean.
If you want to optimize for storage capability, you can store your bits in bytes and evaluate each position using bitmasks. Only really valuable if you have > 8*<length of your unpacking code> booleans to store
yes, that is what I am trying to go for
The reason that boolean sizes aren't defined is that its not relevant for functionality but that you want booleans to fetch as quickly as possible. X86 can fetch BYTE, WORD, DWORD, QWORD and is optimized for fetching blocks of four (QWORD) - hence why you want to align your structures on qword boundaries
https://cdrdv2-public.intel.com/671488/248966-046A-software-optimization-manual.pdf See chapter 3.4.1.4
got it. We (I) usually never have to think on this low level. Mechanical un-sympathetic 😂
In c++ its a structure called bitset https://cplusplus.com/reference/bitset/bitset/
Basically, you need many bools
Java also has it, no?
Javas Bitset does not optimize for size
yes, let's ignore that for now
Do we want to optimize for size or no?
yes, optimize for size
Обсуждают сегодня