Похожие чаты

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 ответов

30 просмотров

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/

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

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- Автор вопроса

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

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

я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Ребят такой вопрос я хочу пранк сделать в колледже и убрать все права установить 000 рекурсивно у домашней директории юзера, установить переменную окружения PATH в "" и сделат...
Super Sigma
21
Всем привет! Массив вводится с клавиатуры, кол-во элементов неизвестно, поэтому я указал arr db 100 dup(?) С нахождением максимума проблем нет, а вот минимум почему-то всегд...
En Vind Av Sorg
11
hi, just reinstalled komodo wallet, and can't find ARRR on there? tried to search ARRR and pirate and nothing came up... is arrr still supported on komodo wallet. it's been ...
Pilner
10
в сях есть множество как в питоне? для удаление дубликатов
Linus
25
Hi everyone, long time no see! 🐼 recently i want to update our Ergo Eco-System map, can everyone help to find out, which to delete and other new to add in? list it, that i can...
HEROKOO
14
55. Hi, how's everything with you?TG大会員2U|82. How's life?TG会員2U|83. Hi, how's everything been treating you?飞机会員2U|84. How's your day been so far?電报会員2U|85. Hey, how's everythi...
Allice Grace
2
читать файл максимально быстро? странный вопрос))
zamtmn
53
I will wait, no problem, I invested in other project also, but with my 8 years experience I can see when something is not good enough. Last bull market everyone was so excited...
jeronim jurakovic
1
If arrr gets implemented on cake wallet. Would that mean arrr/xmr swaps possible in cake wallet like atomic swaps on komodowallet ?
Keks Meister 🏴‍☠️
22
Карта сайта