Похожие чаты

I am puzzled by a Java data type question. I

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

15 ответов

62 просмотра

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

Roy- Автор вопроса

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

BinaryByter
The reason that boolean sizes aren't defined is th...

https://cdrdv2-public.intel.com/671488/248966-046A-software-optimization-manual.pdf See chapter 3.4.1.4

Roy- Автор вопроса
BinaryByter
The reason that boolean sizes aren't defined is th...

got it. We (I) usually never have to think on this low level. Mechanical un-sympathetic 😂

BinaryByter
do this

In c++ its a structure called bitset https://cplusplus.com/reference/bitset/bitset/

Basically, you need many bools

Roy- Автор вопроса
Roy
Java also has it, no?

Javas Bitset does not optimize for size

Roy- Автор вопроса
Roy
yes, let's ignore that for now

Do we want to optimize for size or no?

Roy- Автор вопроса

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта