Documentation ¶
Overview ¶
Package mmap provides the cross-platform memory mapped file I/O.
Index ¶
- Variables
- type Flag
- type Mapping
- func (m *Mapping) Address() uintptr
- func (m *Mapping) Begin(offset int64, length uintptr) (*transaction.Tx, error)
- func (m *Mapping) Close() error
- func (m *Mapping) Executable() bool
- func (m *Mapping) Length() uintptr
- func (m *Mapping) Lock() error
- func (m *Mapping) Memory() []byte
- func (m *Mapping) ReadAt(buf []byte, offset int64) (int, error)
- func (m *Mapping) Segment() *segment.Segment
- func (m *Mapping) Sync() error
- func (m *Mapping) Unlock() error
- func (m *Mapping) Writable() bool
- func (m *Mapping) WriteAt(buf []byte, offset int64) (int, error)
- type Mode
Constants ¶
This section is empty.
Variables ¶
var ErrBadLength = fmt.Errorf("mmap: bad length")
ErrBadOffset is an error which returns when the given length is not valid.
var ErrBadMode = fmt.Errorf("mmap: bad mode")
ErrBadMode is an error which returns when the given mapping mode is not valid.
var ErrBadOffset = fmt.Errorf("mmap: bad offset")
ErrBadOffset is an error which returns when the given offset is not valid.
var ErrClosed = fmt.Errorf("mmap: mapping closed")
ErrClosed is the error which returns when tries to access the closed mapping.
var ErrLocked = fmt.Errorf("mmap: mapping already locked")
ErrLocked is the error which returns when the mapping memory pages were already locked.
var ErrNotLocked = fmt.Errorf("mmap: mapping is not locked")
ErrNotLocked is the error which returns when the mapping memory pages are not locked.
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.
ErrUnavailable is the error which returns when tries to accessing the data which is not available.
Functions ¶
This section is empty.
Types ¶
type Mapping ¶
type Mapping struct {
// contains filtered or unexported fields
}
Mapping is a mapping of the file into the memory.
func Open ¶
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) Close ¶
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 ¶
Executable returns true if the mapped memory pages may be executed.
func (*Mapping) Lock ¶
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) ReadAt ¶
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) WriteAt ¶
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 )