allocator

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvancePointer added in v0.4.0

func AdvancePointer(p unsafe.Pointer, shift uintptr) unsafe.Pointer

AdvancePointer adds shift value to 'p' pointer.

func Alloc

func Alloc(memory []byte, object interface{}) error

Alloc copies value's data into a byte slice performing some sanity checks. The object either must be a slice, or should be a sort of an object, which does not contain any references inside, i.e. should be placed in the memory continuously. If the object is a pointer it will be dereferenced. To alloc a pointer as is, use uintptr or unsafe.Pointer. If the object is a slice, only actual data is stored. the calling site must save object's length and capacity.

func ByteSliceData

func ByteSliceData(slice []byte) unsafe.Pointer

ByteSliceData returns a pointer to the data of the given byte slice

func ByteSliceFromUnsafePointer

func ByteSliceFromUnsafePointer(memory unsafe.Pointer, length, capacity int) []byte

ByteSliceFromUnsafePointer returns a slice of bytes with given length and capacity. Memory pointed by the unsafe.Pointer is used for the slice.

func ByteSliceTointSlice

func ByteSliceTointSlice(memory []byte, length, capacity int) []int

ByteSliceTointSlice returns an int slice, which uses the same memory, that the byte slice uses.

func CheckObjectReferences

func CheckObjectReferences(object interface{}) error

CheckObjectReferences checks if an object of type can be safely copied byte by byte. the object must not contain any reference types like maps, strings, and so on. slices or pointers can be at the top level only

func IntSliceFromUnsafePointer added in v0.2.0

func IntSliceFromUnsafePointer(memory unsafe.Pointer, length, capacity int) []int

IntSliceFromUnsafePointer returns a slice of ints with given length and capacity. Memory pointed by the unsafe.Pointer is used for the slice.

func IsReferenceType

func IsReferenceType(object interface{}) bool

IsReferenceType returns true, is the object is a pointer or a slice

func ObjectAddress

func ObjectAddress(object reflect.Value) unsafe.Pointer

ObjectAddress returns the address of the given object if a slice or a pointer is passed, it will returns a pointer to the actual data

func ObjectData

func ObjectData(object interface{}) ([]byte, error)

ObjectData returns objects underlying byte representation. The object must stored continuously in the memory, ie must not contain any references. Slices of plain objects are allowed.

func ObjectSize

func ObjectSize(object reflect.Value) int

ObjectSize returns the size of the object. If an object is a slice, it returns the size of the entire slice If an object is a pointer, it dereferences the pointer and returns the size of the underlying object.

func RawSliceFromUnsafePointer added in v0.2.0

func RawSliceFromUnsafePointer(memory unsafe.Pointer, length, capacity int) unsafe.Pointer

RawSliceFromUnsafePointer returns a pointer to the slice of ints with given length and capacity. Memory pointed by the unsafe.Pointer is used for the slice.

func Use

func Use(unsafe.Pointer)

Use was taken from syscall package: Use is a no-op, but the compiler cannot see that it is. Calling Use(p) ensures that p is kept live until that point.

func UseValue

func UseValue(value interface{})

UseValue is an ugly hack used to ensure, that the value is alive at some point. It allows to send messages in mq without encoding into []byte, ex:

data, _ = allocator.ObjectData(&received)
mqr.Receive(data)
... work with data
allocator.UseBytes(data)

Types

This section is empty.

Jump to

Keyboard shortcuts

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