Package com.kenai.jffi
Class PageManager
java.lang.Object
com.kenai.jffi.PageManager
Manages allocation, disposal and protection of native memory pages
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe memory should be executablestatic final intThe memory should be readablestatic final intThe memory should be writable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract longallocatePages(int npages, int protection) Allocates native memory pages.abstract voidfreePages(long address, int npages) Free pages allocated viaallocatePages(int, int)static PageManagerGets the page manager for the current platform.final longpageSize()Gets the system page size.abstract voidprotectPages(long address, int npages, int protection) Sets the protection mask on a memory region.
-
Field Details
-
PROT_EXEC
public static final int PROT_EXECThe memory should be executable- See Also:
-
PROT_READ
public static final int PROT_READThe memory should be readable- See Also:
-
PROT_WRITE
public static final int PROT_WRITEThe memory should be writable- See Also:
-
-
Constructor Details
-
PageManager
public PageManager()
-
-
Method Details
-
getInstance
Gets the page manager for the current platform.- Returns:
- An instance of
PageManager
-
pageSize
public final long pageSize()Gets the system page size.- Returns:
- The size of a page on the current system, in bytes.
-
allocatePages
public abstract long allocatePages(int npages, int protection) Allocates native memory pages. The memory allocated is aligned on a page boundary, and the size of the allocated memory isnpages*pageSize.- Parameters:
npages- The number of pages to allocate.protection- The initial protection for the page. This must be a bitmask ofPROT_READ,PROT_WRITEandPROT_EXEC.- Returns:
- The native address of the allocated memory.
-
freePages
public abstract void freePages(long address, int npages) Free pages allocated viaallocatePages(int, int)- Parameters:
address- The memory address as returned fromallocatePages(int, int)npages- The number of pages to free.
-
protectPages
public abstract void protectPages(long address, int npages, int protection) Sets the protection mask on a memory region.- Parameters:
address- The start of the memory region.npages- The number of pages to protect.protection- The protection mask.
-