本文整理了Java中com.sun.jna.Memory.share()
方法的一些代码示例,展示了Memory.share()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Memory.share()
方法的具体详情如下:
包路径:com.sun.jna.Memory
类名称:Memory
方法名:share
[英]Provide a view of this memory using the given offset as the base address. The returned Pointer will have a size equal to that of the original minus the offset.
[中]使用给定的偏移量作为基址,提供该内存的视图。返回的指针的大小将等于原始指针的大小减去偏移量。
代码示例来源:origin: net.java.dev.jna/jna
/** Provide a view of this memory using the given offset as the base address. The
* returned {@link Pointer} will have a size equal to that of the original
* minus the offset.
* @throws IndexOutOfBoundsException if the requested memory is outside
* the allocated bounds.
*/
@Override
public Pointer share(long offset) {
return share(offset, size() - offset);
}
代码示例来源:origin: net.java.dev.jna/jna
/** 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 power of two.
*/
public Memory align(int byteBoundary) {
if (byteBoundary <= 0) {
throw new IllegalArgumentException("Byte boundary must be positive: " + byteBoundary);
}
for (int i=0;i < 32;i++) {
if (byteBoundary == (1<<i)) {
long mask = ~((long)byteBoundary - 1);
if ((peer & mask) != peer) {
long newPeer = (peer + byteBoundary - 1) & mask;
long newSize = peer + size - newPeer;
if (newSize <= 0) {
throw new IllegalArgumentException("Insufficient memory to align to the requested boundary");
}
return (Memory)share(newPeer - peer, newSize);
}
return this;
}
}
throw new IllegalArgumentException("Byte boundary must be a power of two");
}
代码示例来源:origin: stackoverflow.com
Memory data = ...;
// mzH = *(MZHeader*) dPtr;
MZHeader mzH = new MZHeader(data);
mzH.read(); // or put this in the MZHeader(Pointer) ctor
// peH = *(PE_Header*)&dPtr[mzH.offsetToPE];
PE_Header peH = new PE_Header(data.share(mzH.offsetToPE));
peH.read(); // or put this in the PE_Header(Pointer) ctor
// peXH = *(PE_ExtHeader*)&dPtr[mzH.offsetToPE + sizeof(PE_Header)];
PE_ExtHeader peXH = new PE_ExtHeader(data.share(mzH.offsetToPE + peH.size()));
peXH.read(); // or put this in the PE_ExtHeader(Pointer) actor
代码示例来源:origin: com.sun.jna/jna
/** 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 power of two.
*/
public Pointer align(int byteBoundary) {
if (byteBoundary <= 0) {
throw new IllegalArgumentException("Byte boundary must be positive: " + byteBoundary);
}
long mask = ~((long)byteBoundary - 1);
if ((peer & ~mask) != peer) {
long newPeer = (peer + ~mask) & mask;
return share(newPeer - peer, peer + size - newPeer);
}
return this;
}
代码示例来源:origin: com.squareup.jnagmp/jnagmp
private Gmp() {
int offset = 0;
for (int i = 0; i < MAX_OPERANDS; ++i) {
this.sharedOperands[i] = new mpz_t(sharedMem.share(offset, mpz_t.SIZE));
__gmpz_init(sharedOperands[i]);
offset += mpz_t.SIZE;
}
this.countPtr = sharedMem.share(offset, Native.SIZE_T_SIZE);
offset += Native.SIZE_T_SIZE;
assert offset == SHARED_MEM_SIZE;
}
代码示例来源:origin: org.elasticsearch/jna
/** Provide a view of this memory using the given offset as the base address. The
* returned {@link Pointer} will have a size equal to that of the original
* minus the offset.
* @throws IndexOutOfBoundsException if the requested memory is outside
* the allocated bounds.
*/
@Override
public Pointer share(long offset) {
return share(offset, size() - offset);
}
代码示例来源:origin: com.sun.jna/jna
/** Provide a view onto this structure from the given offset. The
* returned {@link Pointer} will have the same size as the original,
* reduced by the offset.
* @throws IndexOutOfBoundsException if the requested memory is outside
* the allocated bounds.
*/
public Pointer share(long offset) {
return share(offset, getSize() - offset);
}
代码示例来源:origin: square/jna-gmp
private Gmp() {
int offset = 0;
for (int i = 0; i < MAX_OPERANDS; ++i) {
this.sharedOperands[i] = new mpz_t(sharedMem.share(offset, mpz_t.SIZE));
__gmpz_init(sharedOperands[i]);
offset += mpz_t.SIZE;
}
this.countPtr = sharedMem.share(offset, Native.SIZE_T_SIZE);
offset += Native.SIZE_T_SIZE;
assert offset == SHARED_MEM_SIZE;
}
代码示例来源:origin: org.elasticsearch/jna
/** 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 power of two.
*/
public Memory align(int byteBoundary) {
if (byteBoundary <= 0) {
throw new IllegalArgumentException("Byte boundary must be positive: " + byteBoundary);
}
for (int i=0;i < 32;i++) {
if (byteBoundary == (1<<i)) {
long mask = ~((long)byteBoundary - 1);
if ((peer & mask) != peer) {
long newPeer = (peer + byteBoundary - 1) & mask;
long newSize = peer + size - newPeer;
if (newSize <= 0) {
throw new IllegalArgumentException("Insufficient memory to align to the requested boundary");
}
return (Memory)share(newPeer - peer, newSize);
}
return this;
}
}
throw new IllegalArgumentException("Byte boundary must be a power of two");
}
代码示例来源:origin: net.java.dev.jna/jna-platform
public void setValue(String value) {
if(value == null) {
value = "";
}
try {
byte[] encodedValue = value.getBytes("UTF-16LE");
// 4 bytes for the length prefix, length for the encoded data,
// 2 bytes for the two NULL terminators
Memory mem = new Memory(4 + encodedValue.length + 2);
mem.clear();
mem.setInt(0, encodedValue.length);
mem.write(4, encodedValue, 0, encodedValue.length);
this.setPointer(mem.share(4));
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException("UTF-16LE charset is not supported", ex);
}
}
代码示例来源:origin: kohsuke/libpam4j
Pointer structBase = mem.share(0);
Pointer bufferBase = mem.share(256);
PointerByReference pbr = new PointerByReference();
int result = libc.getpwnam_r(userName, structBase, bufferBase, 4096, pbr);
内容来源于网络,如有侵权,请联系作者删除!