MCPcopy Create free account
hub / github.com/java-native-access/jna / align

Method align

src/com/sun/jna/Memory.java:162–182  ·  view source on GitHub ↗

Provide a view onto this structure with the given alignment. @param byteBoundary Align memory to this number of bytes; should be a power of two. @throws IndexOutOfBoundsException if the requested alignment can not be met. @throws IllegalArgumentException if the requested alignment is not a positive

(int byteBoundary)

Source from the content-addressed store, hash-verified

160 * a positive power of two.
161 */
162 public Memory align(int byteBoundary) {
163 if (byteBoundary <= 0) {
164 throw new IllegalArgumentException("Byte boundary must be positive: " + byteBoundary);
165 }
166 for (int i=0;i < 32;i++) {
167 if (byteBoundary == (1<<i)) {
168 long mask = ~((long)byteBoundary - 1);
169
170 if ((peer & mask) != peer) {
171 long newPeer = (peer + byteBoundary - 1) & mask;
172 long newSize = peer + size - newPeer;
173 if (newSize <= 0) {
174 throw new IllegalArgumentException("Insufficient memory to align to the requested boundary");
175 }
176 return (Memory)share(newPeer - peer, newSize);
177 }
178 return this;
179 }
180 }
181 throw new IllegalArgumentException("Byte boundary must be a power of two");
182 }
183
184 /** Free the native memory and set peer to zero */
185 @Override

Callers 3

testAlignmentMethod · 0.95
testNegativeAlignmentMethod · 0.95
testInvalidAlignmentMethod · 0.95

Calls 1

shareMethod · 0.95

Tested by 3

testAlignmentMethod · 0.76
testNegativeAlignmentMethod · 0.76
testInvalidAlignmentMethod · 0.76