Documentation ¶
Overview ¶
File memory MAP
The fmap package implements a nice way to memory map a file for block oriented operations. It's interface is block oriented and allows you to allocate and free blocks inside of the file. To support resizing the underlying file outstanding pointers are tracked and are expected to be released. This is done through run time checking.
Index ¶
- Constants
- Variables
- func MemClr(bytes []byte)
- type BlockFile
- func (self *BlockFile) Address() uintptr
- func (self *BlockFile) Allocate() (offset uint64, err error)
- func (self *BlockFile) AllocateBlocks(n int) (offset uint64, err error)
- func (self *BlockFile) BlockSize() int
- func (self *BlockFile) Close() error
- func (self *BlockFile) ControlData() (data []byte, err error)
- func (self *BlockFile) Do(offset, blocks uint64, do func([]byte) error) error
- func (self *BlockFile) Free(offset uint64) error
- func (self *BlockFile) Get(offset, blocks uint64) ([]byte, error)
- func (self *BlockFile) Path() string
- func (self *BlockFile) Release(bytes []byte) error
- func (self *BlockFile) Remove() error
- func (self *BlockFile) SetControlData(data []byte) (err error)
- func (self *BlockFile) SetControlDataNoSync(data []byte) (err error)
- func (self *BlockFile) Size() (uint64, error)
- func (self *BlockFile) Sync() error
- func (self *BlockFile) Valid(address uintptr) bool
Constants ¶
const BLOCKSIZE = 4096
Variables ¶
The flag used when creating the file
The flag used when opening the file
Functions ¶
func MemClr ¶
func MemClr(bytes []byte)
Zero the bytes of the passed in slice. It uses the length not the capacity of the slice. It uses the libc function memset under the hood to do this. Go has an implementation of this function in assembly in the runtime package but I could not find a nice way to expose it. So here is the libc version exposed (via several method calls and the cgo interface).
Types ¶
type BlockFile ¶
type BlockFile struct {
// contains filtered or unexported fields
}
A BlockFile represents the memory mapped file. It has a blocksize all operations are done as block aligned operations.
func Anonymous ¶
Create an anonymous blockfile. There is no backing file. The blocksize must be divisible by 4096 as usual
func CreateBlockFile ¶
Create a blockfile with the standard block size (4096 which is normally the OS page size).
func CreateBlockFileCustomBlockSize ¶
Create a blockfile with a custom blocksize. Note, the size must be a multiple of 4096.
func OpenBlockFile ¶
Open a previously created BlockFile. This will fail if you didn't use the creation functions to create the file (or at least have undefined effects).
func (*BlockFile) Address ¶
What is the address of the file in the address space of the program. Use this at your own risk!
func (*BlockFile) AllocateBlocks ¶
Allocate n blocks. Return the offset of the first block. These are guarranteed to be sequential. This always causes a file resize at the moment.
func (*BlockFile) ControlData ¶
Get the "control data" this free form data which is stored in the control block file. You can put whatever you want in here.
func (*BlockFile) Do ¶
Load the blocks at the give offset then call the callback, `do`, passing in the loaded bytes. This function releases those bytes after your callback is done. This is the recommended interface to the contents of the memory mapped region.
func (*BlockFile) Free ¶
Free the block at the given offset. The offset is in bytes from the start of the file.
func (*BlockFile) Get ¶
Get the bytes at the offset and block count. You probably want to use Do instead. You must call Release() on the bytes when done.
func (*BlockFile) Release ¶
Release() bytes aquired with Get(). Should error if the bytes where not allocated from the mapping. But why take chances, you probably want to use the Do interface instead.
func (*BlockFile) SetControlData ¶
Put user data into the control block of the file.
func (*BlockFile) SetControlDataNoSync ¶
Same as SetControlData but does not call Sync() at the end.