Package org.nustaq.offheap.bytez

Examples of org.nustaq.offheap.bytez.Bytez


        }

    }

    private void grow() {
        final Bytez newBase = alloc.alloc(base.length()*2);
        base.copyTo(newBase,0,0,base.length());
        alloc.free(base);
        base = (MallocBytez) newBase;
        System.out.println("index grew to "+base.length()/1024/1024);
    }
View Full Code Here


        }
        rebase(originBase);
    }

    public void applySnapshot(FSTStruct target) {
        Bytez arr = target.getBase();
        int baseIdx = (int) target.getOffset();
        int snapIdx = 0;
        for (int i = 0; i < curIndex; i++) {
            int changeOffset = changeOffsets[i];
            int len = changeLength[i];
            for ( int ii = 0; ii < len; ii++) {
                arr.put(baseIdx+changeOffset+ii,snapshot[snapIdx++]);
            }
        }
    }
View Full Code Here

    public <T extends FSTStruct> T toStruct(T onHeap, BytezAllocator alloc) {
        if ( onHeap.isOffHeap() ) {
            return onHeap;
        }
        try {
            Bytez b = toByteArray(onHeap, alloc);
            return (T)createWrapper(onHeap.getClass(),b,0);
        } catch (Exception e) {
            if ( e instanceof RuntimeException )
                throw (RuntimeException)e;
            else
View Full Code Here

    }

    public Bytez toByteArray(FSTStruct onHeapStruct, BytezAllocator allocator) {
        try {
            int sz = align(calcStructSize(onHeapStruct),SIZE_ALIGN);
            Bytez b = allocator.alloc(sz);
            toByteArray(onHeapStruct,b,0);
            return b;
        } catch (Exception e) {
            if ( e instanceof RuntimeException )
                throw (RuntimeException)e;
View Full Code Here

                } else {
                    Object[] objArr = (Object[]) o;
                    int elemSiz = bytes.getInt(en.pointerPos+8);
                    siz = Array.getLength(o) * elemSiz;
                    int tmpIndex = index;
                    Bytez templatearr = null;
                    boolean hasClzId = false;
                    if ( onHeapStruct instanceof FSTArrayElementSizeCalculator ) {
                        Class elemClz = ((FSTArrayElementSizeCalculator)onHeapStruct).getElementType(en.fi.getField(),this);
                        if ( elemClz != null ) {
                            int clid = getClzId(elemClz);
                            bytes.putInt(en.pointerPos + 12, clid);
                            hasClzId = true;
                        }
                    }
                    if (en.template != null) {
                        templatearr = toByteArray(en.template); // fixme: unnecessary alloc
                        if ( ! hasClzId ) {
                            bytes.putInt(en.pointerPos + 12, getClzId(en.template.getClass()));
                            hasClzId = true;
                        }
                    }
                    for (int j = 0; j < objArr.length; j++) {
                        Object objectValue = objArr[j];
                        if ( templatearr != null ) {
//                            unsafe.copyMemory(templatearr,FSTStruct.bufoff,bytes,FSTStruct.bufoff+tmpIndex,templatearr.length);
                            templatearr.copyTo(bytes,tmpIndex,0,templatearr.length());
                            tmpIndex+=elemSiz;
                        } else {
                            if ( objectValue == null ) {
                                bytes.putInt(tmpIndex + 4, -1);
                                tmpIndex += elemSiz;
View Full Code Here

TOP

Related Classes of org.nustaq.offheap.bytez.Bytez

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.