Documentation ¶
Index ¶
- Constants
- Variables
- func OpenFile(path string) (*os.File, error)
- func UnsafeBytesToString(bytes []byte) string
- func UnsafeStringToBytes(s string) []byte
- type Flag
- type Mapping
- func (m *Mapping) Address() uintptr
- 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) Read(buf []byte) (int, error)
- func (m *Mapping) ReadAt(buf []byte, offset int64) (int, error)
- func (m *Mapping) Seek(offset int64, whence int) (int64, 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) Write(buf []byte) (int, error)
- func (m *Mapping) WriteAt(buf []byte, offset int64) (int, error)
- type Mode
Constants ¶
const MaxInt = int(^uint(0) >> 1)
MaxInt is the maximum platform dependent signed integer.
Variables ¶
var ( ErrBadMode = fmt.Errorf("mmap: bad mode") ErrBadOffset = fmt.Errorf("mmap: bad offset") ErrBadLength = fmt.Errorf("mmap: bad length") ErrClosed = fmt.Errorf("mmap: mapping closed") ErrLocked = fmt.Errorf("mmap: mapping already locked") ErrNotLocked = fmt.Errorf("mmap: mapping is not locked") ErrOutOfBounds = fmt.Errorf("mmap: out of bounds") ErrReadOnly = fmt.Errorf("mmap: mapping is read only") ErrSeekWhence = errors.New("mmap: invalid seek whence") ErrSeekOffset = errors.New("mmap: invalid seek offset") )
Functions ¶
func UnsafeBytesToString ¶
UnsafeBytesToString converts bytes to string saving allocations
func UnsafeStringToBytes ¶
UnsafeStringToBytes converts bytes to string saving allocations by re-using
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 OpenFileMapping ¶
func OpenFileMapping(name string, perm os.FileMode, size uintptr, flags Flag, init func(mf *Mapping) error) (*Mapping, error)
OpenMappedFile 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) 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 ¶
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 ¶
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) Read ¶
Read reads len(buf) bytes from the internal offset from the mapped memory. If the offset is out of the available bounds or there are not enough bytes to read the ErrOutOfBounds error will be returned. Otherwise len(buf) will be returned with no errors. Read implements the io.Reader interface.
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 out of the available bounds or there are not enough bytes to read the ErrOutOfBounds error will be returned. Otherwise len(buf) will be returned with no errors. ReadAt implements the io.ReaderAt interface.
func (*Mapping) Seek ¶
Seek sets the offset for the next Read or Write to offset, interpreted according to whence: SeekStart means relative to the start of the file, SeekCurrent means relative to the current offset, and SeekEnd means relative to the end. Seek returns the new offset relative to the start of the file and an error, if any. Seeking to an offset before the start of the file is an error. Seeking to any positive offset is legal, but the behavior of subsequent I/O operations on the underlying object is implementation-dependent.
func (*Mapping) Writable ¶
func (m *Mapping) Writable() bool
Writable returns true if the mapped memory pages may be written.
func (*Mapping) Write ¶
Write writes len(buf) bytes from the internal offset into the mapped memory. If the offset is out of the available bounds or there are not enough space to write all given bytes the ErrOutOfBounds error will be returned. Otherwise len(buf) will be returned with no errors. Write implements the io.Writer 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 out of the available bounds or there are not enough space to write all given bytes the ErrOutOfBounds error will be returned. 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 )