shm

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: BSD-3-Clause Imports: 16 Imported by: 7

README

Tools to create and manage shared memory (POSIX Shared memory) across all Unix variants. Pure Go, no external dependencies. Implements Go versions of shm_open() and shm_unlink() that interoperate with the libc versions.

Documentation

Index

Constants

View Source
const NUM_BYTES_FOR_SIZE = 4
View Source
const SHM_DIR = "/dev/shm"

Variables

View Source
var ErrPatternHasSeparator = errors.New("The specified pattern has file path separators in it")
View Source
var ErrPatternTooLong = errors.New("The specified pattern for the SHM name is too long")
View Source
var ErrRegionTooSmall = errors.New("mmaped region too small")

Functions

func Fallocate_simple

func Fallocate_simple(fd int, size int64) (err error)

func RandomFilename

func RandomFilename() string

func Read

func Read(self MMap, b []byte) (n int, err error)

func ReadWithSize

func ReadWithSize(self MMap, at int) ([]byte, error)
func ReadWithSizeAndUnlink(name string, file_callback ...func(fs.FileInfo) error) ([]byte, error)
func ShmUnlink(name string) error

func UnsafeBytesToString

func UnsafeBytesToString(b []byte) (s string)

Unsafely converts b into a string. If you modify b, then s will also be modified. This violates the property that strings are immutable.

func UnsafeStringToBytes

func UnsafeStringToBytes(s string) (b []byte)

Unsafely converts s into a byte slice. If you modify b, then s will also be modified. This violates the property that strings are immutable.

func Write

func Write(self MMap, b []byte) (n int, err error)

func WriteWithSize

func WriteWithSize(self MMap, b []byte, at int) error

Types

type AccessFlags

type AccessFlags int
const (
	READ AccessFlags = iota
	WRITE
	COPY
)

type ErrNotSupported

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

func (*ErrNotSupported) Error

func (self *ErrNotSupported) Error() string

type MMap

type MMap interface {
	Close() error
	Unlink() error
	Slice() []byte
	Name() string
	IsFileSystemBacked() bool
	FileSystemName() string
	Stat() (fs.FileInfo, error)
	Flush() error
	Seek(offset int64, whence int) (ret int64, err error)
	Read(b []byte) (n int, err error)
	Write(b []byte) (n int, err error)
}

func CreateTemp

func CreateTemp(pattern string, size uint64) (MMap, error)

func Open

func Open(name string, size uint64) (MMap, error)

Jump to

Keyboard shortcuts

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