public void getBytes(Bytez target, int startIndexInTarget) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } if (target.length() < startIndexInTarget + getByteSize()) { throw new RuntimeException("ArrayIndexOutofBounds byte len:" + target.length() + " start+size:" + (startIndexInTarget + getByteSize())); } // unsafe.copyMemory(___bytes,___offset, target, bufoff+startIndexInTarget, getByteSize()); ___bytes.copyTo(target, startIndexInTarget, ___offset, getByteSize()); }
public void getBytes(Bytez target, int startIndexInTarget) { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } if (target.length() < startIndexInTarget + getByteSize()) { throw new RuntimeException("ArrayIndexOutofBounds byte len:" + target.length() + " start+size:" + (startIndexInTarget + getByteSize())); } // unsafe.copyMemory(___bytes,___offset, target, bufoff+startIndexInTarget, getByteSize()); ___bytes.copyTo(target, startIndexInTarget, ___offset, getByteSize()); }
@NoAssist public E createPointer(int index) { if ( ! isOffHeap() ) throw new RuntimeException("must be offheap to call this"); E res = (E) elemsPointer(); res.___elementSize = res.getByteSize(); res.___offset+=index*res.___elementSize; return res; }
@Override public boolean equals(Object obj) { if (obj instanceof FSTStruct) { FSTStruct other = (FSTStruct) obj; final int len = getByteSize(); if (other.getByteSize() == len) { long ix = getOffset(); long ox = other.getOffset(); for (int i = 0; i < len; i++) { if (___bytes.get(i + ix) != other.___bytes.get(i + ox)) return false; } return true; } else return false; } return super.equals(obj); }
/** * @return a temporary per thread instance of ByteBuffer pointing to this structs data. The length of the * buffer is same as the length of this struct. * * The instance returned is valid until the currentThread calls this method next time. * * Can be used to feed e.g. NIO api. Use ByteBuffer.duplicate() to obtain a non-temporary instance * * @throws NoSuchFieldException * @throws IllegalAccessException */ public ByteBuffer asByteBufferTemporary() { if ( getBase() instanceof MallocBytez ) { MallocBytez base = (MallocBytez) getBase(); ByteBuffer bb = tmpBuf.get(); try { address.setLong(bb, base.getBaseAdress() + getOffset()); capacity.setInt( bb, getByteSize()); } catch (IllegalAccessException e) { FSTUtil.<RuntimeException>rethrow(e); } bb.limit((int) (getOffset() + getByteSize())); bb.position((int) getOffset()); return tmpBuf.get(); } else { // assume HeapBytez. Allocates return ByteBuffer.wrap(getBase().asByteArray(), (int) getOffset(), getByteSize()); } }
/** * returns a complete copy of this object allocating a new Bytez capable of holding the data. * * @return */ public FSTStruct createCopy() { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } byte b[] = new byte[getByteSize()]; HeapBytez res = new HeapBytez(b); getBytes(res, 0); return ___fac.createStructWrapper(res, 0); }
@NoAssist public E createPointer(int index) { if ( ! isOffHeap() ) throw new RuntimeException("must be offheap to call this"); E res = (E) elemsPointer(); res.___elementSize = res.getByteSize(); res.___offset+=index*res.___elementSize; return res; }
@Override public boolean equals(Object obj) { if (obj instanceof FSTStruct) { FSTStruct other = (FSTStruct) obj; final int len = getByteSize(); if (other.getByteSize() == len) { long ix = getOffset(); long ox = other.getOffset(); for (int i = 0; i < len; i++) { if (___bytes.get(i + ix) != other.___bytes.get(i + ox)) return false; } return true; } else return false; } return super.equals(obj); }
public int hashCode() { if (!isOffHeap()) return onHeapHashcode(); return ___bytes.getInt(___offset) ^ ___bytes.getInt(___offset + getByteSize() - 4); }
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; } }
/** * @return a temporary per thread instance of ByteBuffer pointing to this structs data. The length of the * buffer is same as the length of this struct. * * The instance returned is valid until the currentThread calls this method next time. * * Can be used to feed e.g. NIO api. Use ByteBuffer.duplicate() to obtain a non-temporary instance * * @throws NoSuchFieldException * @throws IllegalAccessException */ public ByteBuffer asByteBufferTemporary() { if ( getBase() instanceof MallocBytez ) { MallocBytez base = (MallocBytez) getBase(); ByteBuffer bb = tmpBuf.get(); try { address.setLong(bb, base.getBaseAdress() + getOffset()); capacity.setInt( bb, getByteSize()); } catch (IllegalAccessException e) { FSTUtil.<RuntimeException>rethrow(e); } bb.limit((int) (getOffset() + getByteSize())); bb.position((int) getOffset()); return tmpBuf.get(); } else { // assume HeapBytez. Allocates return ByteBuffer.wrap(getBase().asByteArray(), (int) getOffset(), getByteSize()); } }
/** * returns a complete copy of this object allocating a new Bytez capable of holding the data. * * @return */ public FSTStruct createCopy() { if (!isOffHeap()) { throw new RuntimeException("must be offheap to call this"); } byte b[] = new byte[getByteSize()]; HeapBytez res = new HeapBytez(b); getBytes(res, 0); return ___fac.createStructWrapper(res, 0); }
public int hashCode() { if (!isOffHeap()) return onHeapHashcode(); return ___bytes.getInt(___offset) ^ ___bytes.getInt(___offset + getByteSize() - 4); }
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; } }
return onHeapStruct.getByteSize(); int siz = 8; FSTClazzInfo clInfo = conf.getClassInfo(onHeapStruct.getClass());
return onHeapStruct.getByteSize(); int siz = 8; FSTClazzInfo clInfo = conf.getClassInfo(onHeapStruct.getClass());
onHeapStruct.___bytes.copyTo(bytes, index, onHeapStruct.___offset, onHeapStruct.getByteSize()); return onHeapStruct.getByteSize();
str = str.toOffHeap(); int byteSize = str.getByteSize(); out.writeInt(byteSize); if ( COMPRESS ) {
onHeapStruct.___bytes.copyTo(bytes, index, onHeapStruct.___offset, onHeapStruct.getByteSize()); return onHeapStruct.getByteSize();
str = str.toOffHeap(); int byteSize = str.getByteSize(); out.writeInt(byteSize); if ( COMPRESS ) {