func CBytes(a Allocator, b []byte) unsafe.Pointer {
	p := a.Malloc(uintptr(len(b)))
	copy(MakeSlice(p, len(b)), b)
	return p
}
CBytes creates a copy of byte slice with given Allocator. It's
analogous to C.CBytes.
package common
import "C"
import (
	"reflect"
	"unsafe"
)
type Allocator interface {
	Malloc(size uintptr) unsafe.Pointer
	Free(p unsafe.Pointer)
	Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer
}
type AllocatorSession struct {
	mem  Allocator
	ptrs map[unsafe.Pointer]struct{}
}
func rootAlloc(mem Allocator) Allocator {
	for {
		if s, ok := mem.(*AllocatorSession); ok {
			mem = s.mem
		} else {
			return mem
		}
	}
}
func NewAllocatorSession(mem Allocator) *AllocatorSession {
	return &AllocatorSession{rootAlloc(mem), make(map[unsafe.Pointer]struct{})}
}
func (s *AllocatorSession) Malloc(size uintptr) unsafe.Pointer {
	p := s.mem.Malloc(size)
	s.ptrs[p] = struct{}{}
	return p
}
func (s *AllocatorSession) Free(p unsafe.Pointer) {
	s.mem.Free(p)
	delete(s.ptrs, p)
}
func (s *AllocatorSession) Realloc(p unsafe.Pointer, size uintptr) unsafe.Pointer {
	p1 := s.mem.Realloc(p, size)
	if p != p1 {
		s.ptrs[p1] = struct{}{}
		delete(s.ptrs, p)
	}
	return p1
}
func (s *AllocatorSession) Flush() {
	for p := range s.ptrs {
		s.mem.Free(p)
	}
	s.ptrs = make(map[unsafe.Pointer]struct{})
}
var _ Allocator = (*AllocatorSession)(nil)
func MallocT(a Allocator, ptr interface{}) unsafe.Pointer {
	return allocArray(a, ptr, 1)
}
func allocArray(a Allocator, ptr interface{}, nmemb int64) unsafe.Pointer {
	v := reflect.ValueOf(ptr)
	t := v.Type().Elem().Elem()
	p := a.Malloc(t.Size() * uintptr(nmemb))
	reflect.Indirect(v).Set(reflect.NewAt(t, p))
	return p
}
func CallocT(a Allocator, ptr interface{}, nmemb interface{}) unsafe.Pointer {
	return allocArray(a, ptr, reflect.ValueOf(nmemb).Int())
}