mem

package
v1.24.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RDONLY maps the memory read-only.
	// Attempts to write to the MemObject object will result in undefined behavior.
	RDONLY = 0
	// RDWR maps the memory as read-write. Writes to the MemObject object will update the
	// underlying file.
	RDWR = 1 << iota
	// COPY maps the memory as copy-on-write. Writes to the MemObject object will affect
	// memory, but the underlying file will remain unchanged.
	COPY
	// EXEC If EXEC is set, the mapped memory is marked as executable.
	EXEC
)
View Source
const (
	// ANON If the ANON flag is set, the mapped memory will not be backed by a file.
	ANON = 1 << iota
)

Variables

This section is empty.

Functions

func FileMap

func FileMap(f *os.File, prot, flags int) ([]byte, error)

FileMap maps an entire file into memory. If ANON is set in flags, f is ignored.

func Lock

func Lock(data []byte) error

Lock 将进程的虚拟内存地址空间中的某段内存锁定在物理内存(RAM)中, 防止被交换到磁盘页面文件

func Unlock

func Unlock(data []byte) error

Unlock 解除内存区域的物理锁定, 允许操作系统再次将内存交换到磁盘

Types

type Object

type Object []byte

Object represents a file mapped into memory.

func OpenMapper

func OpenMapper(f *os.File, prot, flags int) (Object, error)

OpenMapper maps an entire file into memory.

If ANON is set in flags, f is ignored.

func OpenMmap

func OpenMmap(size int, f *os.File) (Object, error)

func (*Object) Bytes

func (m *Object) Bytes() []byte

func (*Object) Flush

func (m *Object) Flush() error

Flush synchronizes the mapping's contents to the file's contents on disk.

func (*Object) Lock

func (m *Object) Lock() error

Lock keeps the mapped region in physical memory, ensuring that it will not be swapped out.

func (*Object) Unlock

func (m *Object) Unlock() error

Unlock reverses the effect of Lock, allowing the mapped region to potentially be swapped out. If m is already unlocked, aan error will result.

func (*Object) Unmap

func (m *Object) Unmap() error

Unmap deletes the memory mapped region, flushes any remaining changes, and sets m to nil. Trying to read or write any remaining references to m after Unmap is called will result in undefined behavior. Unmap should only be called on the slice value that was originally returned from a call to FileMap. Calling Unmap on a derived slice may cause errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL