Alan, Just ensure you get the correct answer for your situation, when you say a lot of access, do you mean read-only or r/w? Concurrency a concern? You say you're looking for the fastest...but do you have any memory limitations to be concerned about?
Cheers, Steve On Wed, Jul 21, 2010 at 10:18 AM, Alan Kent <[email protected]> wrote: > I was wondering what the fastest way (most highly performant) was to parse > data structures serialized as an array of bytes. In my case its like a > network packet (a true array of bytes where I need to peel of 1, 2, 4, and 8 > byte integers, or variable length ASCII (8-bit) strings, etc.) > > Note I am after the FASTEST way to do this in Java (and/or Scala). Is it > better to use the stream based classes, or is it better to do direct array > accesses and do bit shift operations and masks with 0xff etc (to strip sign > extension Java will do otherwise)? I suspect the stream based approaches > would be slower. Sample code that sneaks in: > > byte b1 = buf[i++]; > byte b2 = buf[i++]; > byte b3 = buf[i++]; > byte b4 = buf[i++]; > int n = (b1 << 24) | ((b2 & 0xff) << 16) | ((b3 & 0xff) << 8) | (b4 & > 0xff); // Must mask with 0xff or else sign extension will mess up the > result. Java does not have unsigned bytes or ints! > > I was looking into array bounds checks, and what I found via Google > indicated that hotspot leaves in array bounds checks as there was only a > minor performance improvement found in practice. This lead me to wonder if > there is a faster way to do the code since I would be doing lots of array > accesses, each with a bounds check. > > Just curious! > > Thanks! > Alan > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
