Documentation
¶
Overview ¶
Package shm implements shared memory objects.
Index ¶
- Constants
- func DestroyMemoryObject(name string) error
- type MemoryObject
- type SharedMemoryObject
- type WindowsNativeMemoryObject
- func (obj *WindowsNativeMemoryObject) Close() error
- func (obj *WindowsNativeMemoryObject) Destroy() error
- func (obj *WindowsNativeMemoryObject) Fd() uintptr
- func (obj *WindowsNativeMemoryObject) IsNative() bool
- func (obj *WindowsNativeMemoryObject) Name() string
- func (obj *WindowsNativeMemoryObject) Size() int64
- func (obj *WindowsNativeMemoryObject) Truncate(size int64) error
Constants ¶
const ( // O_COPY_ON_WRITE used as a flag for NewWindowsNativeMemoryObject. // It is passed to CreateFileMapping and OpebFileMapping calls. // Its value was chosen simply not to intersect with O_RDONLY and O_RDWR. O_COPY_ON_WRITE = syscall.O_NONBLOCK )
Variables ¶
This section is empty.
Functions ¶
func DestroyMemoryObject ¶
DestroyMemoryObject permanently removes given memory object.
Types ¶
type MemoryObject ¶
type MemoryObject struct {
// contains filtered or unexported fields
}
MemoryObject represents an object which can be used to map shared memory regions into the process' address space.
func NewMemoryObject ¶
NewMemoryObject creates a new shared memory object.
name - a name of the object. should not contain '/' and exceed 255 symbols (30 on darwin). size - object size. flag - flag is a combination of open flags from 'os' package. perm - object's permission bits.
func (*MemoryObject) Close ¶
func (obj *MemoryObject) Close() error
Close closes object's underlying file object. Darwin: a call to Close() causes invalid argument error, if the object was not truncated. So, in this case we return nil as an error.
func (*MemoryObject) Destroy ¶
func (obj *MemoryObject) Destroy() error
Destroy closes the object and removes it permanently.
func (*MemoryObject) Fd ¶
func (obj *MemoryObject) Fd() uintptr
Fd returns a descriptor of the object's underlying file object.
func (*MemoryObject) Name ¶
func (obj *MemoryObject) Name() string
Name returns the name of the object as it was given to NewMemoryObject().
func (*MemoryObject) Size ¶
func (obj *MemoryObject) Size() int64
Size returns the current object size. Darwin: it may differ from the size passed passed to Truncate.
func (*MemoryObject) Truncate ¶
func (obj *MemoryObject) Truncate(size int64) error
Truncate resizes the shared memory object. Darwin: it is possible to truncate an object only once after it was created. Darwin: the size should be divisible by system page size, otherwise the size is set to the nearest page size divider greater, then the given size.
type SharedMemoryObject ¶
SharedMemoryObject is an interface, which must be implemented by any implemetation of an object used for mapping into memory.
func NewMemoryObjectSize ¶ added in v0.2.0
func NewMemoryObjectSize(name string, flag int, perm os.FileMode, size int64) (SharedMemoryObject, bool, error)
NewMemoryObjectSize opens or creates a shared memory object with the given name. If the object was created, it is truncated to 'size'. Otherwise, checks, that the existing object is at least 'size' bytes long. Returns an object, true, if it was created, and an error.
type WindowsNativeMemoryObject ¶
type WindowsNativeMemoryObject struct {
// contains filtered or unexported fields
}
WindowsNativeMemoryObject represents a standart windows shm implementation backed by a paging file. Can be used to map shared memory regions into the process' address space. It does not follow the usual memory object semantics, and it is destroyed only when all its handles are closed. The following functions were added to satisfy SharedMemoryObject interface and return an error:
Truncate Destroy
func NewWindowsNativeMemoryObject ¶
func NewWindowsNativeMemoryObject(name string, flag, size int) (*WindowsNativeMemoryObject, error)
NewWindowsNativeMemoryObject returns a new Windows native shared memory object.
name - object name. flag - combination of open flags from 'os' package along with O_COPY_ON_WRITE. size - mapping file size.
func (*WindowsNativeMemoryObject) Close ¶
func (obj *WindowsNativeMemoryObject) Close() error
Close closes mapping file object.
func (*WindowsNativeMemoryObject) Destroy ¶
func (obj *WindowsNativeMemoryObject) Destroy() error
Destroy returns an error. It is not supported for windows shared memory.
func (*WindowsNativeMemoryObject) Fd ¶
func (obj *WindowsNativeMemoryObject) Fd() uintptr
Fd returns windows.InvalidHandle so that the paging file is used for mapping.
func (*WindowsNativeMemoryObject) IsNative ¶ added in v0.2.0
func (obj *WindowsNativeMemoryObject) IsNative() bool
IsNative returns true, indicating, that this object can be mapped without extra call to CreateFileMapping.
func (*WindowsNativeMemoryObject) Name ¶
func (obj *WindowsNativeMemoryObject) Name() string
Name returns the name of the object as it was given to NewWindowsNativeMemoryObject().
func (*WindowsNativeMemoryObject) Size ¶
func (obj *WindowsNativeMemoryObject) Size() int64
Size returns mapping fiel size.
func (*WindowsNativeMemoryObject) Truncate ¶
func (obj *WindowsNativeMemoryObject) Truncate(size int64) error
Truncate returns an error. You can specify the size when calling NewWindowsNativeMemoryObject.