本文整理汇总了Java中org.apache.ignite.internal.util.GridUnsafe.allocateMemory方法的典型用法代码示例。如果您正苦于以下问题:Java GridUnsafe.allocateMemory方法的具体用法?Java GridUnsafe.allocateMemory怎么用?Java GridUnsafe.allocateMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.internal.util.GridUnsafe
的用法示例。
在下文中一共展示了GridUnsafe.allocateMemory方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allocatePool
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* Allocate pool memory.
*
* @return Pool pointer.
*/
public static long allocatePool() {
long poolPtr = GridUnsafe.allocateMemory(POOL_HDR_LEN);
GridUnsafe.setMemory(poolPtr, POOL_HDR_LEN, (byte)0);
flags(poolPtr + POOL_HDR_OFF_MEM_1, FLAG_POOLED);
flags(poolPtr + POOL_HDR_OFF_MEM_2, FLAG_POOLED);
flags(poolPtr + POOL_HDR_OFF_MEM_3, FLAG_POOLED);
return poolPtr;
}
示例2: nextRegion
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public DirectMemoryRegion nextRegion() {
if (regions.size() == sizes.length)
return null;
long chunkSize = sizes[regions.size()];
long ptr;
try {
ptr = GridUnsafe.allocateMemory(chunkSize);
}
catch (IllegalArgumentException e) {
String msg = "Failed to allocate next memory chunk: " + U.readableSize(chunkSize, true) +
". Check if chunkSize is too large and 32-bit JVM is used.";
if (regions.size() == 0)
throw new IgniteException(msg, e);
U.error(log, msg);
return null;
}
if (ptr <= 0) {
U.error(log, "Failed to allocate next memory chunk: " + U.readableSize(chunkSize, true));
return null;
}
DirectMemoryRegion region = new UnsafeChunk(ptr, chunkSize);
regions.add(region);
return region;
}
示例3: allocateMemory
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** */
private void allocateMemory(int rows, int cols) {
ptr = GridUnsafe.allocateMemory((long)rows * cols * Double.BYTES);
ptrInitHash = Long.hashCode(ptr);
}
示例4: allocateMemory
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** */
private void allocateMemory(int size) {
ptr = GridUnsafe.allocateMemory(size * Double.BYTES);
ptrInitHash = Long.hashCode(ptr);
}
示例5: start
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public void start() throws IgniteException {
trackingArrPtr = GridUnsafe.allocateMemory(trackingSize * 4);
GridUnsafe.setMemory(trackingArrPtr, trackingSize * 4, (byte)0);
}
示例6: start
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public void start() throws IgniteException {
trackingArrPtr = GridUnsafe.allocateMemory(trackingSize * 8);
GridUnsafe.setMemory(trackingArrPtr, trackingSize * 8, (byte)0);
}
示例7: testOffheapBinary
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* @throws Exception If failed.
*/
public void testOffheapBinary() throws Exception {
BinaryObjectBuilder builder = builder("Class");
builder.setField("i", 111);
builder.setField("f", 111.111f);
builder.setField("iArr", new int[] {1, 2, 3});
builder.setField("obj", new Key(1));
builder.setField("col", Arrays.asList(new Value(1), new Value(2)), Collection.class);
BinaryObject po = builder.build();
byte[] arr = ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
long ptr = GridUnsafe.allocateMemory(arr.length + 5);
try {
long ptr0 = ptr;
GridUnsafe.putBoolean(null, ptr0++, false);
int len = arr.length;
if (BIG_ENDIAN)
GridUnsafe.putIntLE(ptr0, len);
else
GridUnsafe.putInt(ptr0, len);
GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr0 + 4, arr.length);
BinaryObject offheapObj = (BinaryObject)
((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
assertEquals(BinaryObjectOffheapImpl.class, offheapObj.getClass());
assertEquals(expectedHashCode("Class"), offheapObj.type().typeId());
assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), offheapObj.hashCode());
assertEquals(111, offheapObj.<Integer>field("i").intValue());
assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
assertTrue(Arrays.equals(new int[] {1, 2, 3}, offheapObj.<int[]>field("iArr")));
assertEquals(1, offheapObj.<BinaryObject>field("obj").<Key>deserialize().i);
List<BinaryObject> list = offheapObj.field("col");
assertEquals(2, list.size());
assertEquals(1, list.get(0).<Value>deserialize().i);
assertEquals(2, list.get(1).<Value>deserialize().i);
assertEquals(po, offheapObj);
assertEquals(offheapObj, po);
}
finally {
GridUnsafe.freeMemory(ptr);
}
}
示例8: convert
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* Convert binary object to it's final state.
*
* @param obj Object.
* @param offheap Offheap flag.
* @return Result.
*/
private BinaryObjectExImpl convert(BinaryObjectExImpl obj, boolean offheap) {
if (offheap) {
byte[] arr = obj.array();
long ptr = GridUnsafe.allocateMemory(arr.length);
ptrs.add(ptr);
GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length);
obj = new BinaryObjectOffheapImpl(obj.context(), ptr, 0, obj.array().length);
}
return obj;
}
示例9: convert
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* Convert binary object to it's final state.
*
* @param obj Object.
* @param offheap Offheap flag.
* @return Result.
*/
private BinaryObjectExImpl convert(BinaryObject obj, boolean offheap) {
BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
if (offheap) {
byte[] arr = obj0.array();
long ptr = GridUnsafe.allocateMemory(arr.length);
ptrs.add(ptr);
GridUnsafe.copyMemory(arr, GridUnsafe.BYTE_ARR_OFF, null, ptr, arr.length);
obj0 = new BinaryObjectOffheapImpl(obj0.context(), ptr, 0, obj0.array().length);
}
return obj0;
}
示例10: copyOffheap
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* @param obj Object.
* @return Offheap address.
*/
private long copyOffheap(BinaryObjectImpl obj) {
byte[] arr = obj.array();
long ptr = GridUnsafe.allocateMemory(arr.length);
GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr, arr.length);
return ptr;
}
示例11: toBinary
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception {
byte[] arr = marsh.marshal(obj);
long ptr = GridUnsafe.allocateMemory(arr.length);
ptrs.add(ptr);
GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr, arr.length);
return new BinaryObjectOffheapImpl(ctx, ptr, 0, arr.length);
}
示例12: toBinary
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception {
byte[] arr = marsh.marshal(obj);
long ptr = GridUnsafe.allocateMemory(arr.length);
ptrs.add(ptr);
GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr, arr.length);
return new BinaryObjectOffheapImpl(binaryContext(marsh), ptr, 0, arr.length);
}
示例13: testUnsafe
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* Test unsafe vs. new.
*/
@SuppressWarnings("JavaDoc")
private static void testUnsafe() throws InterruptedException {
X.println("Testing unsafe...");
int MAX = 1000000;
long[] addrs = new long[MAX];
System.gc();
GridTimer t = new GridTimer("unsafe");
int mem = 1024;
for (int i = 0; i < MAX; i++) {
addrs[i] = GridUnsafe.allocateMemory(mem);
GridUnsafe.putByte(addrs[i] + RAND.nextInt(mem), (byte)RAND.nextInt(mem));
v = GridUnsafe.getByte(addrs[i] + RAND.nextInt(mem));
}
X.println("Unsafe [time=" + t.stop() + "ms, v=" + v + ']');
Thread.sleep(5000L);
for (long l : addrs)
GridUnsafe.freeMemory(l);
}
示例14: allocate
import org.apache.ignite.internal.util.GridUnsafe; //导入方法依赖的package包/类
/**
* Allocate memory.
*
* @param cap Capacity.
* @return Pointer.
*/
protected long allocate(int cap) {
return GridUnsafe.allocateMemory(cap);
}