/** * @param mappedFile a until that able to map block of memory to a file * @throws IllegalStateException if the block size is not a power of 2 */ public ChronicleUnsafe(@NotNull MappedFile mappedFile) { long blockSize = mappedFile.blockSize(); if (((blockSize & -blockSize) != blockSize)) throw new IllegalStateException("the block size has to be a power of 2"); this.mappedFile = mappedFile; this.chunkSize = mappedFile.blockSize(); long shift = (int) (Math.log(blockSize) / Math.log(2)); mask = ~((1L << shift) - 1L); }
@Deprecated() public static MappedByteBuffer getMap(@NotNull FileChannel fileChannel, long start, int size) throws IOException { return MappedFile.getMap(fileChannel, start, size); }
public long toAddress0(long address) { int index = (int) ((address / chunkSize)); long remainder = address - (((long) index) * chunkSize); // index == 0 is the header, so we wont reference count the header if (mappedMemory != null && mappedMemory.index() != 0) mappedFile.release(mappedMemory); try { this.mappedMemory = mappedFile.acquire(index); } catch (IOException e) { throw new RuntimeException(e); } long result = mappedMemory.bytes().address() + remainder; this.offset = result - address; this.last = mask & address; return result; }
public MappedMemory acquire(long index) throws IOException { MappedMemory map0 = this.map0, map1 = this.map1; if (map0 != null && map0.index() == index) { map0.reserve(); return map0; } if (map1 != null && map1.index() == index) { map1.reserve(); return map1; } return acquire0(index); }
public long toAddress0(long address) { int index = (int) ((address / chunkSize)); long remainder = address - (((long) index) * chunkSize); // index == 0 is the header, so we wont reference count the header if (mappedMemory != null && mappedMemory.index() != 0) mappedFile.release(mappedMemory); try { this.mappedMemory = mappedFile.acquire(index); } catch (IOException e) { throw new RuntimeException(e); } long result = mappedMemory.bytes().address() + remainder; this.offset = result - address; this.last = mask & address; return result; }
public MappedMemory acquire(long index) throws IOException { MappedMemory map0 = this.map0, map1 = this.map1; if (map0 != null && map0.index() == index) { map0.reserve(); return map0; } if (map1 != null && map1.index() == index) { map1.reserve(); return map1; } return acquire0(index); }
/** * @param mappedFile a until that able to map block of memory to a file * @throws IllegalStateException if the block size is not a power of 2 */ public ChronicleUnsafe(@NotNull MappedFile mappedFile) { long blockSize = mappedFile.blockSize(); if (((blockSize & -blockSize) != blockSize)) throw new IllegalStateException("the block size has to be a power of 2"); this.mappedFile = mappedFile; this.chunkSize = mappedFile.blockSize(); long shift = (int) (Math.log(blockSize) / Math.log(2)); mask = ~((1L << shift) - 1L); }