Aligned long views over byte arrays and heap ByteBuffers
Paul Sandoz
paul.sandoz at oracle.com
Wed Jan 20 14:15:06 UTC 2016
> On 20 Jan 2016, at 14:27, Vitaly Davidovich <vitalyd at gmail.com> wrote:
>
> Hi Paul,
>
> isAligned(int,int) could probably use a better name since it's not returning a boolean.
Yeah, "isAligned(…) == 0” is the boolean producing expression.
> How about alignIndex(int,int)?
>
That might work, although it implies returning an aligned index rather than a modulus associated with the current index and unit size. I think that would be more precise if we include boolean argument for rounding up/down to the nearest aligned index:
alignedIndex(int index, int unitSize, boolean roundUp)
For rounding down a negative value might be returned. I still prefer a modulus returning method.
> By the way, what's the rationale behind adding new APIs vs the runtime detection option we discussed earlier?
>
So we don’t have to deal with two separate software and hardware implementations, with a runtime switch, since alignment cannot always be determined statically for buffers.
Requiring explicit alignment is simpler, and arguably the performance characteristics are clearer.
Paul.
More information about the valhalla-dev
mailing list