Documentation
¶
Overview ¶
This package offers the MMap type that manipulates a memory mapped file or device.
IMPORTANT NOTE (1): The MMap type is backed by an unsafe memory region, which is not covered by the normal rules of Go's memory management. If a slice is taken out of it, and then the memory is explicitly unmapped through one of the available methods, both the MMap value itself and the slice obtained will now silently point to invalid memory. Attempting to access data in them will crash the application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdviseFlags ¶
type AdviseFlags uint
const ( MADV_NORMAL AdviseFlags = 0x0 MADV_RANDOM AdviseFlags = 0x1 MADV_SEQUENTIAL AdviseFlags = 0x2 MADV_WILLNEED AdviseFlags = 0x3 MADV_DONTNEED AdviseFlags = 0x4 MADV_REMOVE AdviseFlags = 0x9 MADV_DONTFORK AdviseFlags = 0xa MADV_DOFORK AdviseFlags = 0xb )
type MMap ¶
type MMap []byte
The MMap type represents a memory mapped file or device. The slice offers direct access to the memory mapped content.
IMPORTANT: Please see note in the package documentation regarding the way in which this type behaves.
func Map ¶
Map creates a new mapping in the virtual address space of the calling process. This function will attempt to map the entire file by using the fstat system call with the provided file descriptor to discover its length.
func MapAt ¶
func MapAt(addr uintptr, fd uintptr, offset, length int64, prot ProtFlags, flags MapFlags) (MMap, error)
MapAt creates a new mapping in the virtual address space of the calling process, using the specified region of the provided file or device. The provided addr parameter will be used as a hint of the address where the kernel should position the memory mapped region. If -1 is provided as length, this function will attempt to map until the end of the provided file descriptor by using the fstat system call to discover its length.
func MapRegion ¶
MapRegion creates a new mapping in the virtual address space of the calling process, using the specified region of the provided file or device. If -1 is provided as length, this function will attempt to map until the end of the provided file descriptor by using the fstat system call to discover its length.
func (MMap) Advise ¶
func (mmap MMap) Advise(advice AdviseFlags) error
Advise advises the kernel about how to handle the mapped memory region in terms of input/output paging within the memory region defined by the mmap slice.
func (MMap) IsResident ¶
IsResident returns a slice of booleans informing whether the respective memory page in mmap was mapped at the time the call was made.
func (MMap) Lock ¶
Lock locks the mapped region defined by the mmap slice, preventing it from being swapped out.
func (MMap) Protect ¶
Protect changes the protection flags for the memory mapped region defined by the mmap slice.
func (MMap) Sync ¶
Sync flushes changes made to the region determined by the mmap slice back to the device. Without calling this method, there are no guarantees that changes will be flushed back before the region is unmapped. The flags parameter specifies whether flushing should be done synchronously (before the method returns) with MS_SYNC, or asynchronously (flushing is just scheduled) with MS_ASYNC.
func (MMap) Unlock ¶
Unlock unlocks the mapped region defined by the mmap slice, allowing it to swap out again.
func (MMap) UnsafeUnmap ¶
UnsafeUnmap deletes the memory mapped region defined by the mmap slice. This will also flush any remaining changes, if necessary. Using mmap or any other slices based on it after this method has been called will crash the application.