boolean[1000] array ?

In an attempt to write a better keyboard handler I would need 4x 256 booleans

now I know that the space is “only” reserved, and as most of them aren’t used, the real memory usage isnt that big especially with booleans

but how bad is this really ? is it bad at all ?

I’ve seen people doing keyboard code with “keys[65536]” to cover all keys =P

http://java.sun.com/j2se/1.5.0/docs/api/java/util/BitSet.html

see also http://en.wikipedia.org/wiki/Bit_field

reading that you might consider http://java.sun.com/javase/6/docs/api/java/util/EnumSet.html

[quote]Enum sets are represented internally as bit vectors. This representation is extremely compact and efficient. The space and time performance of this class should be good enough to allow its use as a high-quality, typesafe alternative to traditional int-based “bit flags.” Even bulk operations (such as containsAll and retainAll) should run very quickly if their argument is also an enum set.
[/quote]

used BitSet, seems nice, thx =)

Don’t take 4k competition discussions / submissions as your guide to good style :stuck_out_tongue:

ya I was just wondering how someone could have done something like that
anyway using BitSets now =)

Booleans use up 32 bits on the stack (ex. boolean a, boolean b, boolean c, boolean d will take up 128 bits) and 8 bits in an array (ex. boolean[16] will also take up 128 bits), so you’re definitely losing a lot of bits as opposed to a BitField. But boolean[1000] is only going to take up 1kb anyway, which isn’t bad. If you’re not hurting for RAM there’s not much reason to worry about it too much.