/** * 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; } }