@Override public void getBooleanArr(long byteIndex, boolean[] target, int elemoff, int numElems) { for ( int i = 0; i < numElems; i++) { target[elemoff+i] = getBool(byteIndex+i); } }
@Override public void setBoolean(long byteIndex, boolean[] o, int elemoff, int numElems) { for ( int i = 0; i < numElems; i++) { put(byteIndex+i, (byte) (o[i+elemoff] ? 1 : 0)); } }
public MMFBytez(String filePath, long length, boolean clearFile) throws Exception { super(0, 0); init( filePath, length, clearFile ); }
protected void init(String file, long length, boolean clearFile) throws Exception { File f = new File(file); if ( f.exists() && clearFile ) { f.delete(); } this.file = f; if ( f.exists() ) { length = f.length(); } RandomAccessFile raf = new RandomAccessFile(f, "rw"); raf.setLength(length); // FIXME: see stackoverflow. does not work always FileChannel fileChannel = raf.getChannel(); this.fileChannel = raf.getChannel(); this.baseAdress = map0(fileChannel, imodeFor(FileChannel.MapMode.READ_WRITE), 0L, length); this.length = length; this.cleaner = Cleaner.create(this, new Unmapper(baseAdress, length, fileChannel)); }
public void free() { checkThread(); mutationCount++; if ( alloc != null ) { alloc.freeAll(); alloc = null; } if ( memory instanceof MMFBytez ) { ((MMFBytez) memory).freeAndClose(); memory = null; } // index.free(); index = null; }
public MallocBytez(long adr, long len) { setBase(adr, len); }
@Override public boolean getBoolVolatile(long byteIndex) { return getVolatile(byteIndex) != 0; }
public MallocBytez slice(long off, int len) { if (off+len >= length) throw new RuntimeException("invalid slice "+off+":"+len+" mylen:"+length); return new MallocBytez(baseAdress+off,len); }
@Override public void putBoolVolatile(long byteIndex, boolean value) { putVolatile(byteIndex, (byte) (value?1:0)); }
@Override public void freeAll() { for (int i = 0; i < allocated.size(); i++) { MallocBytez mallocBytez = allocated.get(i); mallocBytez.free(); } allocated.clear(); } }
@Override public void putBool(long byteIndex, boolean val) { put(byteIndex, (byte) (val ? 1 : 0)); }
public MallocBytez(long adr, long len) { setBase(adr, len); }
@Override public void getBooleanArr(long byteIndex, boolean[] target, int elemoff, int numElems) { for ( int i = 0; i < numElems; i++) { target[elemoff+i] = getBool(byteIndex+i); } }
public MMFBytez(String filePath, long length, boolean clearFile) throws Exception { super(0, 0); init( filePath, length, clearFile ); }
@Override public boolean getBoolVolatile(long byteIndex) { return getVolatile(byteIndex) != 0; }
@Override public BasicBytez newInstance(long size) { return new MallocBytez(unsafe.allocateMemory(size),size); }
@Override public void setBoolean(long byteIndex, boolean[] o, int elemoff, int numElems) { for ( int i = 0; i < numElems; i++) { put(byteIndex+i, (byte) (o[i+elemoff] ? 1 : 0)); } }
public Object toObject(long address, int availableSize) throws IOException, ClassNotFoundException { in.resetForReuse(null); readTarget.setBase(address,availableSize); Object o = in.readObject(); return o; }
@Override public void putBool(long byteIndex, boolean val) { put(byteIndex, (byte) (val ? 1 : 0)); }
/** * throws FSTBufferTooSmallException in case object does not fit into given range * * @param o * @param address * @param availableSize * @throws IOException * @return number of bytes written to the memory region */ public int toMemory(Object o, long address, int availableSize) throws IOException { out.resetForReUse(); writeTarget.setBase(address, availableSize); out.writeObject(o); int written = out.getWritten(); return written; }