public <T extends FSTStruct> T toStruct(T onHeap) { return toStruct(onHeap,allocator); }
public <T extends FSTStruct> T toStruct(T onHeap) { return toStruct(onHeap,allocator); }
/** * @param onHeapTemplate * @param <T> * @return return a byte array based struct instance for given on-heap template. Allocates a new byte[] with each call */ public static <T extends FSTStruct> T toStruct(T onHeapTemplate) { return FSTStructFactory.getInstance().toStruct(onHeapTemplate); }
public <T extends FSTStruct> StructArray<T> toStructArray(int size, T onHeap) { StructArray<T> arr = new StructArray<T>(size,onHeap); return toStruct(arr); }
/** * @param onHeapTemplate * @param <T> * @return return a byte array based struct instance for given on-heap template. Allocates a new byte[] with each call */ public static <T extends FSTStruct> T toStruct(T onHeapTemplate) { return FSTStructFactory.getInstance().toStruct(onHeapTemplate); }
public <T extends FSTStruct> StructArray<T> toStructArray(int size, T onHeap) { StructArray<T> arr = new StructArray<T>(size,onHeap); return toStruct(arr); }
public FSTStruct toOffHeap() { if (isOffHeap()) return this; return FSTStructFactory.getInstance().toStruct(this); }
public FSTStruct toOffHeap() { if (isOffHeap()) return this; return FSTStructFactory.getInstance().toStruct(this); }
/** * create a new struct array of same type as template * @param size * @return */ public <X extends FSTStruct> StructArray<X> newArray(int size, X templ, BytezAllocator alloc) { StructArray<X> aTemplate = new StructArray<X>(size, templ); int siz = getFactory().calcStructSize(aTemplate); try { if ( siz < chunkSize ) return newStruct(aTemplate); else { return getFactory().toStruct(aTemplate,alloc); } } catch (Throwable e) { throw new RuntimeException(e); } }
/** * create a new struct array of same type as template * @param size * @return */ public <X extends FSTStruct> StructArray<X> newArray(int size, X templ, BytezAllocator alloc) { StructArray<X> aTemplate = new StructArray<X>(size, templ); int siz = getFactory().calcStructSize(aTemplate); try { if ( siz < chunkSize ) return newStruct(aTemplate); else { return getFactory().toStruct(aTemplate,alloc); } } catch (Throwable e) { throw new RuntimeException(e); } }
public <S extends FSTStruct> S newStruct(S aTemplate, BytezAllocator alloc) { aTemplate = getFactory().toStruct(aTemplate); if (aTemplate.getByteSize()>=chunkSize) return (S)aTemplate.createCopy(); int byteSize = aTemplate.getByteSize(); synchronized (this) { if (chunk == null || chunkIndex+byteSize >= chunk.length()) { chunk = alloc.alloc(chunkSize); if ( DUMP_ALLOC ) System.out.println("[Allocator] sum allocated "+MallocBytezAllocator.alloced.get()/1024/1024+" MB"); chunkIndex = 0; chunkObjCount = 0; } // FSTStruct.unsafe.copyMemory(aTemplate.___bytes, aTemplate.___offset, chunk, FSTStruct.bufoff + chunkIndex, byteSize); aTemplate.___bytes.copyTo(chunk, chunkIndex, aTemplate.___offset, byteSize); S res = (S) getFactory().createStructWrapper(chunk, chunkIndex ); chunkIndex+=byteSize; chunkObjCount++; return res; } }
public <S extends FSTStruct> S newStruct(S aTemplate, BytezAllocator alloc) { aTemplate = getFactory().toStruct(aTemplate); if (aTemplate.getByteSize()>=chunkSize) return (S)aTemplate.createCopy(); int byteSize = aTemplate.getByteSize(); synchronized (this) { if (chunk == null || chunkIndex+byteSize >= chunk.length()) { chunk = alloc.alloc(chunkSize); if ( DUMP_ALLOC ) System.out.println("[Allocator] sum allocated "+MallocBytezAllocator.alloced.get()/1024/1024+" MB"); chunkIndex = 0; chunkObjCount = 0; } // FSTStruct.unsafe.copyMemory(aTemplate.___bytes, aTemplate.___offset, chunk, FSTStruct.bufoff + chunkIndex, byteSize); aTemplate.___bytes.copyTo(chunk, chunkIndex, aTemplate.___offset, byteSize); S res = (S) getFactory().createStructWrapper(chunk, chunkIndex ); chunkIndex+=byteSize; chunkObjCount++; return res; } }