本文整理匯總了Java中com.sun.jna.Native.malloc方法的典型用法代碼示例。如果您正苦於以下問題:Java Native.malloc方法的具體用法?Java Native.malloc怎麽用?Java Native.malloc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.jna.Native
的用法示例。
在下文中一共展示了Native.malloc方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: allocate
import com.sun.jna.Native; //導入方法依賴的package包/類
public static long allocate(long size)
{
long sizeInMb = size/1048576;
long totalSizeInMb = ALLOCATED_SIZE.addAndGet(size)/1048576;
LOGGER.info("Allocating off-heap memory block of " + sizeInMb +
"Mb and total allocated off-heap memory size is " + totalSizeInMb + "Mb");
long retAddr = Native.malloc(size);
memTracker.put(retAddr, size);
return retAddr;
}
示例2: memory_malloc_jna
import com.sun.jna.Native; //導入方法依賴的package包/類
@Benchmark
public void memory_malloc_jna() {
long native_p = Native.malloc(100);
ByteSlice buffer = ByteSlice.wrap(MemoryUtil.getByteBuffer(native_p, 100, true));
for (int i = 0; i < 100; i++) {
buffer.put(i, (byte) i);
}
//Native.free(native_p);
}
示例3: memory_malloc_jna2
import com.sun.jna.Native; //導入方法依賴的package包/類
@Benchmark
public void memory_malloc_jna2() {
long native_p = Native.malloc(100);
ByteSlice buffer = ByteSlice.wrap(MemoryUtil.getByteBuffer(native_p, 100, true));
for (int i = 0; i < 100; i++) {
buffer.put(i, (byte) i);
}
Pointer.createConstant(native_p);
//Native.free(native_p);
}
示例4: memory_malloc_jna3
import com.sun.jna.Native; //導入方法依賴的package包/類
@Benchmark
public void memory_malloc_jna3() {
long native_p = Native.malloc(100);
ByteSlice buffer = ByteSlice.wrap(MemoryUtil.getByteBuffer(native_p, 100, true));
for (int i = 0; i < 100; i++) {
buffer.put(i, (byte) i);
}
buffer.asPointer();
//Native.free(native_p);
}
示例5: memory_get_set_pointer
import com.sun.jna.Native; //導入方法依賴的package包/類
@Benchmark
public void memory_get_set_pointer() {
long p = Native.malloc(1000);
Pointer pointer = new Pointer(p);
pointer.setByte(10, (byte) 10);
byte b = pointer.getByte(10);
Native.free(p);
}
示例6: memory_get_set_directbytebuffer
import com.sun.jna.Native; //導入方法依賴的package包/類
@Benchmark
public void memory_get_set_directbytebuffer() {
long p = Native.malloc(1000);
ByteSlice slice = ByteSlice.fromAddress(p, 1000, false);
slice.put(10, (byte) 10);
byte b = slice.get(10);
Native.free(p);
}
示例7: MemoryBuffer
import com.sun.jna.Native; //導入方法依賴的package包/類
public MemoryBuffer(int size) {
super(Native.malloc(size));
this.size = size;
}
示例8: allocate
import com.sun.jna.Native; //導入方法依賴的package包/類
public static long allocate(long size) {
return Native.malloc(size);
}
示例9: memory_malloc_free_jna
import com.sun.jna.Native; //導入方法依賴的package包/類
@Benchmark
public void memory_malloc_free_jna() {
long p = Native.malloc(1000);
Native.free(p);
}