Package io.atomix.utils.memory
Class MappedMemoryAllocator
- java.lang.Object
-
- io.atomix.utils.memory.MappedMemoryAllocator
-
- All Implemented Interfaces:
MemoryAllocator<MappedMemory>
public class MappedMemoryAllocator extends Object implements MemoryAllocator<MappedMemory>
Mapped memory allocator.The mapped memory allocator provides direct memory access to memory mapped from a file on disk. The mapped allocator supports allocating memory in any
FileChannel.MapMode. Once the file is mapped and the memory has been allocated, the mapped allocator provides the memory address of the underlyingMappedByteBufferfor access viaUnsafe.- Author:
- Jordan Halterman
-
-
Field Summary
Fields Modifier and Type Field Description static FileChannel.MapModeDEFAULT_MAP_MODE
-
Constructor Summary
Constructors Constructor Description MappedMemoryAllocator(File file)MappedMemoryAllocator(File file, FileChannel.MapMode mode)MappedMemoryAllocator(File file, FileChannel.MapMode mode, long offset)MappedMemoryAllocator(RandomAccessFile file, FileChannel.MapMode mode, long offset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MappedMemoryallocate(int size)Allocates memory.voidclose()MappedMemoryreallocate(MappedMemory memory, int size)Reallocates the given memory.
-
-
-
Field Detail
-
DEFAULT_MAP_MODE
public static final FileChannel.MapMode DEFAULT_MAP_MODE
-
-
Constructor Detail
-
MappedMemoryAllocator
public MappedMemoryAllocator(File file)
-
MappedMemoryAllocator
public MappedMemoryAllocator(File file, FileChannel.MapMode mode)
-
MappedMemoryAllocator
public MappedMemoryAllocator(File file, FileChannel.MapMode mode, long offset)
-
MappedMemoryAllocator
public MappedMemoryAllocator(RandomAccessFile file, FileChannel.MapMode mode, long offset)
-
-
Method Detail
-
allocate
public MappedMemory allocate(int size)
Description copied from interface:MemoryAllocatorAllocates memory.- Specified by:
allocatein interfaceMemoryAllocator<MappedMemory>- Parameters:
size- The count of the memory to allocate.- Returns:
- The allocated memory.
-
reallocate
public MappedMemory reallocate(MappedMemory memory, int size)
Description copied from interface:MemoryAllocatorReallocates the given memory.When the memory is reallocated, the memory address for the given
Memoryinstance may change. The returnedMemoryinstance will contain the updated address and count.- Specified by:
reallocatein interfaceMemoryAllocator<MappedMemory>- Parameters:
memory- The memory to reallocate.size- The count to which to reallocate the given memory.- Returns:
- The reallocated memory.
-
close
public void close()
-
-