当前位置: 首页>>代码示例>>Java>>正文


Java GridUnsafe.allocateMemory方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:ignite,代码行数:17,代码来源:PlatformMemoryUtils.java

示例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;
}
 
开发者ID:apache,项目名称:ignite,代码行数:37,代码来源:UnsafeMemoryProvider.java

示例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);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:7,代码来源:DenseOffHeapMatrixStorage.java

示例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);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:7,代码来源:DenseLocalOffHeapVectorStorage.java

示例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);
}
 
开发者ID:apache,项目名称:ignite,代码行数:7,代码来源:RandomLruPageEvictionTracker.java

示例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);
}
 
开发者ID:apache,项目名称:ignite,代码行数:7,代码来源:Random2LruPageEvictionTracker.java

示例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);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:60,代码来源:BinaryObjectBuilderDefaultMappersSelfTest.java

示例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;
}
 
开发者ID:apache,项目名称:ignite,代码行数:23,代码来源:BinarySerialiedFieldComparatorSelfTest.java

示例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;
}
 
开发者ID:apache,项目名称:ignite,代码行数:25,代码来源:BinaryArrayIdentityResolverSelfTest.java

示例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;
}
 
开发者ID:apache,项目名称:ignite,代码行数:14,代码来源:BinaryMarshallerSelfTest.java

示例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);
}
 
开发者ID:apache,项目名称:ignite,代码行数:13,代码来源:BinaryFooterOffsetsOffheapSelfTest.java

示例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);
}
 
开发者ID:apache,项目名称:ignite,代码行数:13,代码来源:BinaryFieldsOffheapSelfTest.java

示例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);
}
 
开发者ID:apache,项目名称:ignite,代码行数:33,代码来源:GridBasicPerformanceTest.java

示例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);
}
 
开发者ID:apache,项目名称:ignite,代码行数:10,代码来源:BinaryOffheapOutputStream.java


注:本文中的org.apache.ignite.internal.util.GridUnsafe.allocateMemory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。