ByteBuffer.AlignmentOffset(Int32, Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the memory address, pointing to the byte at the given index, modulo the given unit size.
[Android.Runtime.Register("alignmentOffset", "(II)I", "", ApiSince=33)]
public int AlignmentOffset (int index, int unitSize);
[<Android.Runtime.Register("alignmentOffset", "(II)I", "", ApiSince=33)>]
member this.AlignmentOffset : int * int -> int
Parameters
- index
- Int32
The index to query for alignment offset, must be non-negative, no upper bounds check is performed
- unitSize
- Int32
The unit size in bytes, must be a power of 2
Returns
The indexed byte's memory address modulo the unit size
- Attributes
Remarks
Returns the memory address, pointing to the byte at the given index, modulo the given unit size.
The return value is non-negative in the range of 0
(inclusive) up to unitSize
(exclusive), with zero indicating that the address of the byte at the index is aligned for the unit size, and a positive value that the address is misaligned for the unit size. If the address of the byte at the index is misaligned, the return value represents how much the index should be adjusted to locate a byte at an aligned address. Specifically, the index should either be decremented by the return value if the latter is not greater than index
, or be incremented by the unit size minus the return value. Therefore given <blockquote>
int value = alignmentOffset(index, unitSize)
</blockquote> then the identities <blockquote>
alignmentOffset(index - value, unitSize) == 0, value ≤ index
</blockquote> and <blockquote>
alignmentOffset(index + (unitSize - value), unitSize) == 0
</blockquote> must hold.
Added in 9.
Java documentation for java.nio.ByteBuffer.alignmentOffset(int, int)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.