Documentation
¶
Index ¶
Constants ¶
const ( // RDONLY maps the memory read-only. // Attempts to write to the MMap object will result in undefined behavior. RDONLY = 0 // RDWR maps the memory as read-write. Writes to the MMap object will update the // underlying file. RDWR = 1 << iota // COPY maps the memory as copy-on-write. Writes to the MMap object will affect // memory, but the underlying file will remain unchanged. COPY // If EXEC is set, the mapped memory is marked as executable. EXEC )
Variables ¶
This section is empty.
Functions ¶
func GetFileSize ¶
GetFileSize gets the file length from its fd
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 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) 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. We use unmap & map again to implement this on windows. So can only change the protect flags on the whole
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.