[antlr-interest] Java boolean type storage
Andy Tripp
antlr at jazillian.com
Thu Nov 2 13:06:05 PST 2006
Steve Lianoglou wrote:
> Hi guys,
>
> I've been casually following this thread and don't have much to say,
> but I would like to point out:
>
>> That's a great example. You make the assumption that an array of
>> booleans is somehow going to be slower or use more memory
>> than a bitvector. You've got to let that old thinking go, Luke! You
>> worry about your application and pick the appropriate
>> data structure for it. Let the compiler and runtime be smart about
>> performance and memory management. It is better at
>> those things than you are (and certainly better than you think it is).
>
>
> At some point an array of booleans (boolean[]) in Java actually used
> one byte to store each bit, so appearances aren't always what they
> seem? That's an 8x bigger data structure than you would have been
> bargaining for ... and sometimes it really does make a difference.
>
> And by "at some point" .. this was seemingly the case in Java 1.2.2.
The place to look would be the JVM spec, which has only this footnote:
In Sun's JDK releases 1.0 and 1.1, and the Java 2 SDK, Standard Edition,
v1.2, |boolean| arrays in the Java programming language are encoded as
Java virtual machine |byte| arrays, using 8 bits per |boolean| element.
So that sounds like you're outta luck for now, but the spec doesn't rule
out a change in the future.
Sorry, I didn't mean to get your hopes up :)
>
> (2) Maybe swerve the conversation to more tangible topics :-)
Not likely :) As with older languages, better to let older threads that
have gone off track
just fade away quietly :)
>
> I should probably ask in comp.lang.java or some such, but how many
> times does this thing come up in a passing conversation? I just
> couldn't resist.
>
> Thanks,
> -steve
>
More information about the antlr-interest
mailing list