Class Mman
- java.lang.Object
-
- com.github.marschall.nativebytebuffers.Mman
-
public final class Mman extends Object
Provides access to memory management usingsys/mman.h
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
getpagesize()
Returns the number of bytes in a memory page, where "page" is a fixed-length block, the unit for memory allocation and file mapping performed bymmap(int, int)
.static ByteBuffer
mmap(int length)
Callsmmap()
to create an anonymous shared virtual memory region and creates aByteBuffer
around it.static ByteBuffer
mmap(int length, int flags)
Callsmmap()
to create a virtual memory region and creates aByteBuffer
around it.static void
munmap(ByteBuffer buffer)
Callsmunmap()
on the contents of the givenByteBuffer
.
-
-
-
Method Detail
-
mmap
public static ByteBuffer mmap(int length)
Callsmmap()
to create an anonymous shared virtual memory region and creates aByteBuffer
around it.Protection will be
PROT_READ | PROT_WRITE
.- Parameters:
length
- the length of the mapping, must be greater than 0- Returns:
- a new ByteBuffer around the newly
mmap()
-ed area, nevernull
, must be released withmunmap(ByteBuffer)
- Throws:
IllegalArgumentException
- iflength
is not positiveAllocationFailedException
- ifmmap()
fails- See Also:
mmap(int, int)
,munmap(ByteBuffer)
, http://man7.org/linux/man-pages/man2/mmap.2.html
-
mmap
public static ByteBuffer mmap(int length, int flags)
Callsmmap()
to create a virtual memory region and creates aByteBuffer
around it.Protection will be
PROT_READ | PROT_WRITE
.- Parameters:
length
- the length of the mapping, must be greater than 0flags
- ORed arguments fromMmapFlags
that control various aspects of the mapping- Returns:
- a new ByteBuffer around the newly
mmap()
-ed area, nevernull
, must be released withmunmap(ByteBuffer)
- Throws:
IllegalArgumentException
- iflength
is not positiveAllocationFailedException
- ifmmap()
fails- See Also:
munmap(ByteBuffer)
, http://man7.org/linux/man-pages/man2/mmap.2.html
-
munmap
public static void munmap(ByteBuffer buffer)
Callsmunmap()
on the contents of the givenByteBuffer
.This method may crash the JVM the buffer passed has not been created by
mmap(int, int)
,mmap(int)
or has already been passed to this method.- Parameters:
buffer
- the buffer to free, notnull
, must have been created withmmap(int, int)
ormmap(int)
, must not be accessed afterwards, must not be passed to this method again- Throws:
NullPointerException
- ifbuffer
isnull
IllegalArgumentException
- ifbuffer
is not a direct bufferReleaseFailedException
- if unmapping fails- See Also:
munmap(ByteBuffer)
, http://man7.org/linux/man-pages/man2/mmap.2.html
-
getpagesize
public static long getpagesize()
Returns the number of bytes in a memory page, where "page" is a fixed-length block, the unit for memory allocation and file mapping performed bymmap(int, int)
.- Returns:
- the page size,
long
because in theory we could have pages larger than 2 GiB - See Also:
- http://man7.org/linux/man-pages/man2/getpagesize.2.html
-
-