_mmap

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: MIT Imports: 3 Imported by: 0

README

使用步骤

定义一个1G的文件

filename := "test2.txt"
size := 1024 * 1024 * 1024

打开文件,获取文件描述符

f, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
if nil != err {
    panic(err)
}
defer func() {
    f.Close()
}()

映射

m := _mmap.Open(f, 0, size, syscall.PROT_WRITE|syscall.PROT_READ, syscall.MAP_SHARED)
defer func() {
    m.Close()
}()

读写

message := "Hello 中国!"
for i := 0; i < 71582788; i++ {
    m.Append([]byte(message))
}

刷盘

m.Flush(syscall.MS_ASYNC)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mmap

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

func Open

func Open(file *os.File, offset int64, size int, prot int, flag int) *Mmap

func (*Mmap) Append

func (this *Mmap) Append(b []byte)

func (*Mmap) Close

func (this *Mmap) Close()

func (*Mmap) Flush

func (this *Mmap) Flush(ms int)

func (*Mmap) Read

func (this *Mmap) Read(offset int64, length int64) []byte

Jump to

Keyboard shortcuts

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