Documentation
¶
Index ¶
- func CalcSharedArraySize(size, elemSize int) int
- type SharedArray
- func (arr *SharedArray) At(i int) []byte
- func (arr *SharedArray) AtPointer(i int) unsafe.Pointer
- func (arr *SharedArray) Cap() int
- func (arr *SharedArray) ElemSize() int
- func (arr *SharedArray) Len() int
- func (arr *SharedArray) PopBack()
- func (arr *SharedArray) PopFront()
- func (arr *SharedArray) PushBack(datas ...[]byte) int
- func (arr *SharedArray) RemoveAt(i int)
- func (arr *SharedArray) SafeLen() int
- func (arr *SharedArray) Swap(i, j int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcSharedArraySize ¶
CalcSharedArraySize returns the size, needed to place shared array in memory.
Types ¶
type SharedArray ¶
type SharedArray struct {
// contains filtered or unexported fields
}
SharedArray is an array placed in the shared memory with fixed length and element size. It is possible to swap elements and pop them from any position. It never moves elements in memory, so can be used to implement an array of futexes or spin locks.
func NewSharedArray ¶
func NewSharedArray(raw unsafe.Pointer, size, elemSize int) *SharedArray
NewSharedArray initializes new shared array with size and element size.
func OpenSharedArray ¶
func OpenSharedArray(raw unsafe.Pointer) *SharedArray
OpenSharedArray opens existing shared array.
func (*SharedArray) At ¶
func (arr *SharedArray) At(i int) []byte
At returns data at the position i. Returned slice references to the data in the array. It does not perform border check.
func (*SharedArray) AtPointer ¶
func (arr *SharedArray) AtPointer(i int) unsafe.Pointer
AtPointer returns pointer to the data at the position i. It does not perform border check.
func (*SharedArray) ElemSize ¶
func (arr *SharedArray) ElemSize() int
ElemSize returns size of the element.
func (*SharedArray) PopBack ¶
func (arr *SharedArray) PopBack()
PopBack removes the last element of the array.
func (*SharedArray) PopFront ¶
func (arr *SharedArray) PopFront()
PopFront removes the first element of the array.
func (*SharedArray) PushBack ¶
func (arr *SharedArray) PushBack(datas ...[]byte) int
PushBack add new element to the end of the array, merging given datas. Returns number of bytes copied, less or equal, than the size of the element.
func (*SharedArray) RemoveAt ¶ added in v0.4.0
func (arr *SharedArray) RemoveAt(i int)
RemoveAt removes i'th element.
func (*SharedArray) SafeLen ¶ added in v0.4.0
func (arr *SharedArray) SafeLen() int
SafeLen atomically loads returns current length.
func (*SharedArray) Swap ¶
func (arr *SharedArray) Swap(i, j int)
Swap swaps two elements of the array.