Cracking the coding says that to make it somewhat more space efficient, we could use a bit vector instead of a boolean array. Any thoughts about the distinctions between these two? Thanks.
Asked
Active
Viewed 2,540 times
2 Answers
1
It is saying this because using the int to store the value (32 bits), is going to use less space than a boolean[256], as each allocated boolean will take up 8 bits (8*256 = 2048).

John
- 376
- 1
- 7
-5
A Bit Vector? In Java? There are possible ways to save bitwise information by using logical operators, but usually the smallest datatype in Java is a char which consists of 8 Bits aka 1 Byte. I would say: Yes you can make it more efficient regarding the used memory, but you will loose some runtime efficiency due to the system is optimized for Int and similar datatypes. (not that it matters)
Java is not made for bitmanipulation though. Use C or assembler instead :)

Schuiram
- 191
- 1
- 1
- 8
-
1`char which consists of 8 Bits`. No. The `char` is 16-bit. `make it more efficient regarding the used memory`. No - not necessarily. Java now can pack multiple booleans into a single byte, which is a huge memory reduction. This makes this design system less effective. `Java is not made for bitmanipulation`. Sorry, guess I'll just remove all the systems I have made so far. – Obicere Apr 14 '14 at 19:29
-
Thanks for giving an actual feedback: 1.) Yes you are right! I meant Byte, just got confused with char in c which is 8 Bit. 2.) I would love to see a reference for that (reg. multiple booleans in a byte), as I think its treated different from system to system - but generally as an int. 3.) Tell me of a more effective way for bitmanipulation in java then there are in C - would love a reference too please. 4.) Java uses mostly INT size for boolean, cause the read and write efficiency. If you are up to memory effeciency you rather take C or alike. – Schuiram Apr 14 '14 at 20:15