mmap

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 10 Imported by: 0

README

MMAP

GitHub release go.dev reference codecov GoDoc License Go Report Card

The MMAP package is a syscall interface to provide safe and efficient access to memory.

Supports for Darwin,Linux and Windows architectures.

Installation

> go get github.com/godcong/mmap@latest

Example

See examples folder

Similar Packages

  • github.com/godcong/mmap
  • golang.org/x/exp/mmap
  • github.com/riobard/godcong
  • launchpad.net/gommap
  • github.com/edsrzf/mmap-go

License

This Project used MIT and BSD license.

Documentation

Index

Constants

View Source
const (
	EINVAL = syscall.EINVAL
	ENOENT = syscall.ENOENT
)
View Source
const (
	PROT_NONE  = syscall.PROT_NONE
	PROT_READ  = syscall.PROT_READ
	PROT_WRITE = syscall.PROT_WRITE
	PROT_EXEC  = syscall.PROT_EXEC

	MAP_SHARED = syscall.MAP_SHARED
)
View Source
const (
	MapMemKeyInvalid = -1
)

Variables

View Source
var (
	ErrBadFileDesc = errors.New("bad file descriptor")
	ErrShortWrite  = io.ErrShortWrite
	ErrInvalid     = os.ErrInvalid
	EOF            = io.EOF
)

Functions

func GenKey

func GenKey() int

GenKey generates a random int id, not including 0.

func Log

func Log() *slog.Logger

func Mlock

func Mlock(b []byte) (err error)

Mlock locks the given byte slice.

It takes a byte slice as a parameter and returns an error.

func Mmap

func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error)

Mmap maps length bytes of the file represented by the file descriptor fd into memory, starting at the byte offset.

fd int - file descriptor offset int64 - byte offset length int - length in bytes prot int - memory protection flags int - mapping flags []byte, error - mapped data and an error

func Munmap

func Munmap(b []byte) (err error)

Munmap unmaps the given byte slice.

It takes a byte slice as a parameter and returns an error.

Types

type MapFile

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

MapFile reads/writes a memory-mapped file.

func Open

func Open(filename string) (*MapFile, error)

Open memory-maps the named file for reading.

func OpenFile

func OpenFile(filename string, flag int, mode os.FileMode) (*MapFile, error)

OpenFile memory-maps the named file for reading/writing, depending on the flag value.

func OpenFileS

func OpenFileS(filename string, flag int, mode os.FileMode, size int) (*MapFile, error)

OpenFileS memory-maps the named file for reading/writing, depending on the flag value.

func (*MapFile) At

func (f *MapFile) At(i int) byte

At returns the byte at index i.

func (*MapFile) Close

func (f *MapFile) Close() error

Close closes the memory-mapped file.

func (*MapFile) Fd

func (f *MapFile) Fd() uintptr

func (*MapFile) Len

func (f *MapFile) Len() int

Len returns the length of the underlying memory-mapped file.

func (*MapFile) Read

func (f *MapFile) Read(p []byte) (int, error)

Read implements the io.Reader interface.

func (*MapFile) ReadAt

func (f *MapFile) ReadAt(p []byte, off int64) (int, error)

ReadAt implements the io.ReaderAt interface.

func (*MapFile) ReadByte

func (f *MapFile) ReadByte() (byte, error)

ReadByte implements the io.ByteReader interface.

func (*MapFile) Seek

func (f *MapFile) Seek(offset int64, whence int) (int64, error)

func (*MapFile) Stat

func (f *MapFile) Stat() (os.FileInfo, error)

Stat returns the MapFileInfo structure describing file. If there is an error, it will be of type *os.PathError.

func (*MapFile) Sync

func (f *MapFile) Sync() error

Sync commits the current contents of the file to stable storage.

func (*MapFile) Write

func (f *MapFile) Write(p []byte) (int, error)

Write implements the io.Writer interface.

func (*MapFile) WriteAt

func (f *MapFile) WriteAt(p []byte, off int64) (int, error)

WriteAt implements the io.WriterAt interface.

func (*MapFile) WriteByte

func (f *MapFile) WriteByte(c byte) error

WriteByte implements the io.ByteWriter interface.

type MapMem

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

func OpenMem

func OpenMem(id int, size int) (*MapMem, error)

func OpenMemS

func OpenMemS(id int) (*MapMem, error)

func (*MapMem) Cap

func (f *MapMem) Cap() int

func (*MapMem) Close

func (f *MapMem) Close() (err error)

func (*MapMem) ID

func (f *MapMem) ID() int

func (*MapMem) IsOwner

func (f *MapMem) IsOwner() bool

func (*MapMem) Len

func (f *MapMem) Len() int

func (*MapMem) Read

func (f *MapMem) Read(p []byte) (int, error)

Read implements the io.Reader interface.

func (*MapMem) ReadAt

func (f *MapMem) ReadAt(p []byte, off int64) (n int, err error)

func (*MapMem) ReadByte

func (f *MapMem) ReadByte() (byte, error)

func (*MapMem) Seek

func (f *MapMem) Seek(offset int64, whence int) (int64, error)

func (*MapMem) Write

func (f *MapMem) Write(p []byte) (int, error)

Write implements the io.Writer interface.

func (*MapMem) WriteAt

func (f *MapMem) WriteAt(p []byte, off int64) (n int, err error)

func (*MapMem) WriteByte

func (f *MapMem) WriteByte(c byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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