Package filealloc

import "github.com/byte-mug/golibs/filealloc"

Overview

This package offers space-management of os.File-like entities.

Each allocation is broken down to a set of simple, atomic steps, so that the file does not get corrupted, if the process or system crashes during an allocation or deallocation.

Index

Variables

var EDoubleFree = fmt.Errorf("Warning: Double Free")

-

var EInternalError = fmt.Errorf("Invalid Offset")

-

var EInvalidOffset = fmt.Errorf("Invalid Offset")

-

func LL_getRawSizeForRank

func LL_getRawSizeForRank(i uint) int

-

type Allocator

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

Allocator manages allocation of file blocks within a File.

Allocator methods are not safe for concurrent use by multiple goroutines. Callers must provide their own synchronization whan it's used concurrently by multiple goroutines.

func NewAllocator

func NewAllocator(f File) (*Allocator, error)

-

func (*Allocator) Alloc

func (a *Allocator) Alloc(size int, noGrow bool) (int64, error)

-

func (*Allocator) ApproxFreeSpace

func (a *Allocator) ApproxFreeSpace() (total int64)

-

func (*Allocator) ApproxFreeSpaceFor

func (a *Allocator) ApproxFreeSpaceFor(minSize int) (total int64)

-

func (*Allocator) FileSize

func (a *Allocator) FileSize() int64

-

func (*Allocator) Free

func (a *Allocator) Free(off int64) error

-

func (*Allocator) LL_getRanks

func (a *Allocator) LL_getRanks() [30]int64

-

func (*Allocator) UsableSize

func (a *Allocator) UsableSize(off int64) (int, error)

-

type File

type File interface {
	Close() error
	ReadAt(p []byte, off int64) (n int, err error)
	Stat() (os.FileInfo, error)
	Sync() error
	Truncate(int64) error
	WriteAt(p []byte, off int64) (n int, err error)
}

*os.File

Dependencies