Package io.atomix.utils.memory
Class MappedMemory
- java.lang.Object
-
- io.atomix.utils.memory.MappedMemory
-
- All Implemented Interfaces:
Memory
public class MappedMemory extends Object implements Memory
Mapped memory.This is a special memory descriptor that handles management of
MappedByteBufferbased memory. The mapped memory descriptor simply points to the memory address of the underlying byte buffer. When memory is reallocated, the parentMappedMemoryAllocatoris used to create a newMappedByteBufferand free the existing buffer.- Author:
- Jordan Halterman
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.atomix.utils.memory.Memory
Memory.Util
-
-
Constructor Summary
Constructors Constructor Description MappedMemory(MappedByteBuffer buffer, MappedMemoryAllocator allocator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MappedMemoryallocate(File file, int size)Allocates memory mapped to a file on disk.static MappedMemoryallocate(File file, FileChannel.MapMode mode, int size)Allocates memory mapped to a file on disk.voidclose()voidflush()Flushes the mapped buffer to disk.voidfree()Frees the memory.intsize()Returns the memory count.
-
-
-
Constructor Detail
-
MappedMemory
public MappedMemory(MappedByteBuffer buffer, MappedMemoryAllocator allocator)
-
-
Method Detail
-
allocate
public static MappedMemory allocate(File file, int size)
Allocates memory mapped to a file on disk.- Parameters:
file- The file to which to map memory.size- The count of the memory to map.- Returns:
- The mapped memory.
- Throws:
IllegalArgumentException- Ifcountis greater thanMAX_SIZE
-
allocate
public static MappedMemory allocate(File file, FileChannel.MapMode mode, int size)
Allocates memory mapped to a file on disk.- Parameters:
file- The file to which to map memory.mode- The mode with which to map memory.size- The count of the memory to map.- Returns:
- The mapped memory.
- Throws:
IllegalArgumentException- Ifcountis greater thanMAX_SIZE
-
flush
public void flush()
Flushes the mapped buffer to disk.
-
size
public int size()
Description copied from interface:MemoryReturns the memory count.
-
free
public void free()
Description copied from interface:MemoryFrees the memory.
-
close
public void close()
-
-