mmap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2019 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package mmap provides the cross-platform memory mapped file I/O.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadLength = fmt.Errorf("mmap: bad length")

ErrBadOffset is an error which returns when the given length is not valid.

View Source
var ErrBadMode = fmt.Errorf("mmap: bad mode")

ErrBadMode is an error which returns when the given mapping mode is not valid.

View Source
var ErrBadOffset = fmt.Errorf("mmap: bad offset")

ErrBadOffset is an error which returns when the given offset is not valid.

View Source
var ErrClosed = fmt.Errorf("mmap: mapping closed")

ErrClosed is the error which returns when tries to access the closed mapping.

View Source
var ErrLocked = fmt.Errorf("mmap: mapping already locked")

ErrLocked is the error which returns when the mapping memory pages were already locked.

View Source
var ErrNotLocked = fmt.Errorf("mmap: mapping is not locked")

ErrNotLocked is the error which returns when the mapping memory pages are not locked.

View Source
var ErrReadOnly = fmt.Errorf("mmap: mapping is read only")

ErrReadOnly is the error which returns when tries to execute a write operation on the read-only mapping.

View Source
var ErrUnavailable = fmt.Errorf("mmap: data not available")

ErrUnavailable is the error which returns when tries to accessing the data which is not available.

Functions

This section is empty.

Types

type Flag

type Flag int

Flag is a mapping flag.

const (
	// Mapped memory pages may be executed.
	FlagExecutable Flag = 1 << iota
)

type Mapping

type Mapping struct {
	// contains filtered or unexported fields
}

Mapping is a mapping of the file into the memory.

func Open

func Open(fd uintptr, offset int64, length uintptr, mode Mode, flags Flag) (*Mapping, error)

Open opens and returns a new mapping of the given file into the memory. The given file descriptor will be duplicated. It means that if the parent file will be closed the mapping will still be valid. Actual offset and length may be different than the given by the reason of aligning to the memory page size.

func OpenFile

func OpenFile(name string, perm os.FileMode, size uintptr, flags Flag, init func(m *Mapping) error) (*Mapping, error)

OpenFile prepares a file, calls the initializer if file was just created and returns a new mapping of the prepared file into the memory.

func (*Mapping) Address

func (m *Mapping) Address() uintptr

Address returns the pointer to the mapped memory.

func (*Mapping) Begin

func (m *Mapping) Begin(offset int64, length uintptr) (*transaction.Tx, error)

Begin starts and returns a new transaction.

func (*Mapping) Close

func (m *Mapping) Close() error

Close closes this mapping and frees all resources associated with it. Mapped memory will be synchronized with the underlying file and unlocked automatically. Close implements the io.Closer interface.

func (*Mapping) Executable

func (m *Mapping) Executable() bool

Executable returns true if the mapped memory pages may be executed.

func (*Mapping) Length

func (m *Mapping) Length() uintptr

Length returns the mapped memory length in bytes.

func (*Mapping) Lock

func (m *Mapping) Lock() error

Lock locks the mapped memory pages. All pages that contain a part of the mapping address range are guaranteed to be resident in RAM when the call returns successfully. The pages are guaranteed to stay in RAM until later unlocked. It may need to increase process memory limits for operation success. See working set on Windows and rlimit on Linux for details.

func (*Mapping) Memory

func (m *Mapping) Memory() []byte

Memory returns the byte slice which wraps the mapped memory.

func (*Mapping) ReadAt

func (m *Mapping) ReadAt(buf []byte, offset int64) (int, error)

ReadAt reads len(buf) bytes at the given offset from start of the mapped memory from the mapped memory. If the given offset is outside of the accessible range the ErrUnavailable error will be returned. If there are not enough bytes to read then will be read how many there is and the number of read bytes will be returned with the ErrUnavailable error. Otherwise len(buf) will be returned with no errors. ReadAt implements the io.ReaderAt interface.

func (*Mapping) Segment

func (m *Mapping) Segment() *segment.Segment

Segment returns the data segment on top of this mapping.

func (*Mapping) Sync

func (m *Mapping) Sync() error

Sync synchronizes the mapped memory with the underlying file.

func (*Mapping) Unlock

func (m *Mapping) Unlock() error

Unlock unlocks the previously locked mapped memory pages.

func (*Mapping) Writable

func (m *Mapping) Writable() bool

Writable returns true if the mapped memory pages may be written.

func (*Mapping) WriteAt

func (m *Mapping) WriteAt(buf []byte, offset int64) (int, error)

WriteAt writes len(buf) bytes at the given offset from start of the mapped memory into the mapped memory. If the given offset is outside of the accessible range the ErrUnavailable error will be returned. If there are not enough space to write all given bytes then will be written as much as possible and the number of written bytes will be returned with the ErrUnavailable error. Otherwise len(buf) will be returned with no errors. WriteAt implements the io.WriterAt interface.

type Mode

type Mode int

Mode is a mapping mode.

const (
	// Share this mapping and allow the read-only access.
	ModeReadOnly Mode = iota

	// Share this mapping.
	// Updates to the mapping are visible to other processes
	// mapping the same region, and are carried through to the underlying file.
	// To precisely control when updates are carried through to the underlying file
	// requires the use of Mapping.Sync.
	ModeReadWrite

	// Create a private copy-on-write mapping.
	// Updates to the mapping are not visible to other processes
	// mapping the same region, and are not carried through to the underlying file.
	// It is unspecified whether changes made to the file are visible in the mapped region.
	ModeWriteCopy
)

Jump to

Keyboard shortcuts

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