--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-symp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You can use direct ByteBuffer to use Unsafe on the platforms which have it. Its not quite as efficient but the overhead is small compared with cache miss costs.
However you might find the int [] and long [] as fast or faster and simpler.
Prefetching works just fine from two arrays instead of one.
--
Note: there is no byte [] for a direct ByteBuffer.
Right. That was a typo. At least in OpenJDK, direct ByteBuffers operate on plain Unsafe-allocated memory.-Aleksey.
On Wed, Mar 19, 2014 at 10:03 PM, Peter Lawrey <peter....@gmail.com> wrote:
Note: there is no byte [] for a direct ByteBuffer.
On 19 Mar 2014 17:59, "Aleksey Shipilev" <aleksey....@gmail.com> wrote:
E. Use DirectByteBuffer which already encapsulates the byte[] storage and full-width Unsafe operations, whether it's int or long.-Aleksey.
On Wed, Mar 19, 2014 at 9:46 PM, Nathan Tippy <natha...@gmail.com> wrote:
I want to read a Java array from beginning to the end to allow good pre-fetch behavior.But the list however is a mix of mostly int with periodic longs. Lets say 5 ints for every long on average.For simplicity I know the index where the longs appear (eg a repeating pattern).NOTE: I also need Android compatibility so I think that would eliminate any Unsafe solutions (Please correct me if I am wrong).Here are my design choices, which would be the most sympathetic?
A. Use int[] and when a long is encountered take something like int[x]<<32 | int[x+1] to rebuild the long.Is the overhead here of the << and | going to hurt too much?B. Use long[] and downcast all the intsIs the extra width padding around the ints going to hurt too much?C. Use two arrays int[] and long[] jumping between them as needed while keeping to position indexes.(existing code does this and I feel that it can be improved, this is why I am asking.)D. any other ideas?
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsub...@googlegroups.com.
Afaik android doesn't have intrinsics for ByteBuffer / Unsafe. This should impact performance.
If performance aren't an obvious issue, I'd rather go for methods like 2 array or any method that is obvious to anyone who reads the code. I'm just guessing Bytebuffer or not wouldn't make much of a difference even with reasonable array size. Just my 2 cents. Btw is good performance wise is ByteBuffer in ARM arch, just curious.
--