Class MappedMemory
java.lang.Object
org.newsclub.net.unix.memory.MappedMemory
- All Implemented Interfaces:
Closeable, AutoCloseable
-
Method Summary
Modifier and TypeMethodDescriptionstatic MappedMemoryanonymousCopyOnWriteSegment(Arena arena, long length) Returns an anonymous copy-on-write (changes are local to the process running this JVM) memory segment of the given length.static MappedMemoryanonymousReadOnlySegment(Arena arena, long length) Returns an anonymous read-only memory segment of the given length.static MappedMemoryanonymousSegment(Arena arena, long length) Returns an anonymous read/write memory segment of the given length.voidclose()static longReturns the system's default memory page allocation size for shared memory.Returns theMemorySegmentbacked by this instance.longReturns the minimum sub-allocation size.mapRegion(long msOffset, long length, FileDescriptor fd, long fdOffset) Maps some memory to a region of thisMappedMemoryobject.static MappedMemoryplaceholderSegment(Arena arena, long length) Returns an anonymous memory segment of the given length that acts as a placeholder for later, memory-mapped segments in this area.
-
Method Details
-
getMemorySegment
Returns theMemorySegmentbacked by this instance.- Returns:
- The
MemorySegment.
-
getMinimumSubAllocationSize
public long getMinimumSubAllocationSize()Returns the minimum sub-allocation size.- Returns:
- The minimum sub-allocation size.
-
defaultAllocationSize
public static long defaultAllocationSize()Returns the system's default memory page allocation size for shared memory.This may be larger than the system's regular page size (e.g., on Windows it's 64k).
- Returns:
- The page size.
-
anonymousReadOnlySegment
Returns an anonymous read-only memory segment of the given length.- Parameters:
arena- The arena to associate theMappedMemoryinstance with.length- The length of the segment.- Returns:
- The
MappedMemorysegment. - Throws:
IOException- on error.
-
anonymousSegment
Returns an anonymous read/write memory segment of the given length.- Parameters:
arena- The arena to associate theMappedMemoryinstance with.length- The length of the segment.- Returns:
- The
MappedMemorysegment. - Throws:
IOException- on error.
-
placeholderSegment
Returns an anonymous memory segment of the given length that acts as a placeholder for later, memory-mapped segments in this area.- Parameters:
arena- The arena to associate theMappedMemoryinstance with.length- The length of the segment.- Returns:
- The
MappedMemorysegment. - Throws:
IOException- on error.
-
anonymousCopyOnWriteSegment
Returns an anonymous copy-on-write (changes are local to the process running this JVM) memory segment of the given length.- Parameters:
arena- The arena to associate theMappedMemoryinstance with.length- The length of the segment.- Returns:
- The
MappedMemorysegment. - Throws:
IOException- on error.
-
mapRegion
public MappedMemory mapRegion(long msOffset, long length, FileDescriptor fd, long fdOffset) throws IOException Maps some memory to a region of thisMappedMemoryobject. This may fail to work on Windows, unlessplaceholderSegment(Arena, long)was used to create thisMappedMemoryinstance.- Parameters:
msOffset- The target offset in this object.length- The number of bytes to map.fd- The file descriptor to map from.fdOffset- The file descriptor-specific content offset- Returns:
- A new
MappedMemoryobject, whoseMemorySegmentis a subrange of this object'sMemorySegment. - Throws:
IOException- on error.- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-