Documentation ¶
Overview ¶
Package mmap provides the cross-platform memory mapped file I/O. Note than all provided tools are not thread safe.
Index ¶
- type ErrorClosed
- type ErrorIllegalOperation
- type ErrorInvalidLength
- type ErrorInvalidMode
- type ErrorInvalidOffset
- type ErrorLocked
- type ErrorPartialCommit
- type ErrorTransactionClosed
- type ErrorUnlocked
- type Flag
- type Mapping
- func (m *Mapping) Address() uintptr
- func (m *Mapping) Begin(offset int64, length uintptr) (*Transaction, 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) Sync() error
- func (m *Mapping) Unlock() error
- func (m *Mapping) Writable() bool
- func (m *Mapping) WriteAt(buf []byte, offset int64) (int, error)
- type Mode
- type Transaction
- func (tx *Transaction) Commit() error
- func (tx *Transaction) Flush() error
- func (tx *Transaction) Length() uintptr
- func (tx *Transaction) Offset() int64
- func (tx *Transaction) ReadAt(buf []byte, offset int64) (int, error)
- func (tx *Transaction) Rollback() error
- func (tx *Transaction) WriteAt(buf []byte, offset int64) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorClosed ¶
type ErrorClosed struct{}
ErrorClosed is an error which returns when tries to access the closed mapping.
func (*ErrorClosed) Error ¶
func (err *ErrorClosed) Error() string
Implementation of the error interface.
type ErrorIllegalOperation ¶ added in v0.2.0
type ErrorIllegalOperation struct{ Operation string }
ErrorIllegalOperation is an error which returns when tries to execute illegal operation for the mapping.
func (*ErrorIllegalOperation) Error ¶ added in v0.2.0
func (err *ErrorIllegalOperation) Error() string
Implementation of the error interface.
type ErrorInvalidLength ¶ added in v0.2.0
type ErrorInvalidLength struct{ Length uintptr }
ErrorInvalidLength is an error which returns when specified length is invalid.
func (*ErrorInvalidLength) Error ¶ added in v0.2.0
func (err *ErrorInvalidLength) Error() string
Implementation of the error interface.
type ErrorInvalidMode ¶
type ErrorInvalidMode struct{ Mode Mode }
ErrorInvalidMode is an error which returns when specified mapping mode is invalid.
func (*ErrorInvalidMode) Error ¶
func (err *ErrorInvalidMode) Error() string
Implementation of the error interface.
type ErrorInvalidOffset ¶
type ErrorInvalidOffset struct{ Offset int64 }
ErrorInvalidOffset is an error which returns when specified offset is invalid.
func (*ErrorInvalidOffset) Error ¶
func (err *ErrorInvalidOffset) Error() string
Implementation of the error interface.
type ErrorLocked ¶ added in v0.2.0
type ErrorLocked struct{}
ErrorLocked is an error which returns when mapping memory pages were already locked.
func (*ErrorLocked) Error ¶ added in v0.2.0
func (err *ErrorLocked) Error() string
Implementation of the error interface.
type ErrorPartialCommit ¶ added in v0.3.0
type ErrorPartialCommit struct{ BytesCommitted int }
ErrorPartialCommit is an error which returns when the transaction was committed partially.
func (*ErrorPartialCommit) Error ¶ added in v0.3.0
func (err *ErrorPartialCommit) Error() string
Implementation of the error interface.
type ErrorTransactionClosed ¶ added in v0.3.0
type ErrorTransactionClosed struct{}
ErrorTransactionClosed is an error which returns when tries to access the closed transaction.
func (*ErrorTransactionClosed) Error ¶ added in v0.3.0
func (err *ErrorTransactionClosed) Error() string
Implementation of the error interface.
type ErrorUnlocked ¶ added in v0.2.0
type ErrorUnlocked struct{}
ErrorUnlocked is an error which returns when mapping memory pages were not locked.
func (*ErrorUnlocked) Error ¶ added in v0.2.0
func (err *ErrorUnlocked) Error() string
Implementation of the error interface.
type Flag ¶ added in v0.2.0
type Flag int
Flags is a mapping flags.
const ( // Mapped memory pages may be executed. FlagExecutable Flag = 0x1 )
type Mapping ¶
type Mapping struct {
// contains filtered or unexported fields
}
Mapping is a mapping of file into the memory.
func New ¶
New returns a new mapping of file into the memory. Actual offset and length may be different than specified by the reason of aligning to page size.
func (*Mapping) Begin ¶ added in v0.2.0
func (m *Mapping) Begin(offset int64, length uintptr) (*Transaction, error)
Begin starts the transaction for this mapping.
func (*Mapping) Close ¶
Close closes this mapping and frees all resources associated with it. Mapping will be synchronized with the underlying file and unlocked automatically. Implementation of io.Closer.
func (*Mapping) Executable ¶ added in v0.2.0
Executable returns true if mapped memory pages may be executed.
func (*Mapping) Lock ¶ added in v0.2.0
Lock locks mapped memory pages. All pages that contain a part of 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 ¶
Read reads len(buf) bytes at given offset from mapped memory. Implementation of io.ReaderAt.
type Mode ¶
type Mode int
Mode is a mapping mode.
const ( // Share this mapping and allow 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 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 )
type Transaction ¶ added in v0.3.0
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a transaction over the mapping. The transaction is not valid if parent mapping is closed.
func NewTransaction ¶ added in v0.3.0
func NewTransaction(m *Mapping, offset int64, length uintptr) (*Transaction, error)
NewTransaction returns a new transaction over the specified mapping. Transaction snapshot allocating into the heap starts at specified offset and has specified length.
func (*Transaction) Commit ¶ added in v0.3.0
func (tx *Transaction) Commit() error
Commit flushes snapshot to mapped memory, closes this transaction and frees all resources associated with it.
func (*Transaction) Flush ¶ added in v0.3.0
func (tx *Transaction) Flush() error
Flush commits this transaction and synchronize parent mapping with the underlying file.
func (*Transaction) Length ¶ added in v0.3.0
func (tx *Transaction) Length() uintptr
Length returns snapshot length in bytes.
func (*Transaction) Offset ¶ added in v0.3.0
func (tx *Transaction) Offset() int64
Offset returns starting offset of this transaction.
func (*Transaction) ReadAt ¶ added in v0.3.0
func (tx *Transaction) ReadAt(buf []byte, offset int64) (int, error)
Read reads len(buf) bytes at given offset relatively to parent mapping address from the snapshot. Implementation of io.ReaderAt.
func (*Transaction) Rollback ¶ added in v0.3.0
func (tx *Transaction) Rollback() error
Rollback closes this transaction and frees all resources associated with it.