func allocDeviceInfoMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfDeviceInfoValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
allocDeviceInfoMemory allocates memory for type C.PaDeviceInfo in C.
The caller is responsible for freeing the this memory via C.free.
package portaudio
import "C"
import (
	"sync"
	"unsafe"
)
type cgoAllocMap struct {
	mux sync.RWMutex
	m   map[unsafe.Pointer]struct{}
}
var cgoAllocsUnknown = new(cgoAllocMap)
func (a *cgoAllocMap) Add(ptr unsafe.Pointer) {
	a.mux.Lock()
	if a.m == nil {
		a.m = make(map[unsafe.Pointer]struct{})
	}
	a.m[ptr] = struct{}{}
	a.mux.Unlock()
}
func (a *cgoAllocMap) IsEmpty() bool {
	a.mux.RLock()
	isEmpty := len(a.m) == 0
	a.mux.RUnlock()
	return isEmpty
}
func (a *cgoAllocMap) Borrow(b *cgoAllocMap) {
	if b == nil || b.IsEmpty() {
		return
	}
	b.mux.Lock()
	a.mux.Lock()
	for ptr := range b.m {
		if a.m == nil {
			a.m = make(map[unsafe.Pointer]struct{})
		}
		a.m[ptr] = struct{}{}
		delete(b.m, ptr)
	}
	a.mux.Unlock()
	b.mux.Unlock()
}
func (a *cgoAllocMap) Free() {
	a.mux.Lock()
	for ptr := range a.m {
		C.free(ptr)
		delete(a.m, ptr)
	}
	a.mux.Unlock()
}
func allocHostApiInfoMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfHostApiInfoValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfHostApiInfoValue = unsafe.Sizeof([1]C.PaHostApiInfo{})
func unpackPCharString(str string) (*C.char, *cgoAllocMap) {
	h := (*stringHeader)(unsafe.Pointer(&str))
	return (*C.char)(unsafe.Pointer(h.Data)), cgoAllocsUnknown
}
type stringHeader struct {
	Data uintptr
	Len  int
}
func packPCharString(p *C.char) (raw string) {
	if p != nil && *p != 0 {
		h := (*stringHeader)(unsafe.Pointer(&raw))
		h.Data = uintptr(unsafe.Pointer(p))
		for *p != 0 {
			p = (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + 1))  
		}
		h.Len = int(uintptr(unsafe.Pointer(p)) - h.Data)
	}
	return
}
type RawString string
func (raw RawString) Copy() string {
	if len(raw) == 0 {
		return ""
	}
	h := (*stringHeader)(unsafe.Pointer(&raw))
	return C.GoStringN((*C.char)(unsafe.Pointer(h.Data)), C.int(h.Len))
}
func (x *HostApiInfo) Ref() *C.PaHostApiInfo {
	if x == nil {
		return nil
	}
	return x.ref2fd9b1fc
}
func (x *HostApiInfo) Free() {
	if x != nil && x.allocs2fd9b1fc != nil {
		x.allocs2fd9b1fc.(*cgoAllocMap).Free()
		x.ref2fd9b1fc = nil
	}
}
func NewHostApiInfoRef(ref unsafe.Pointer) *HostApiInfo {
	if ref == nil {
		return nil
	}
	obj := new(HostApiInfo)
	obj.ref2fd9b1fc = (*C.PaHostApiInfo)(unsafe.Pointer(ref))
	return obj
}
func (x *HostApiInfo) PassRef() (*C.PaHostApiInfo, *cgoAllocMap) {
	if x == nil {
		return nil, nil
	} else if x.ref2fd9b1fc != nil {
		return x.ref2fd9b1fc, nil
	}
	mem2fd9b1fc := allocHostApiInfoMemory(1)
	ref2fd9b1fc := (*C.PaHostApiInfo)(mem2fd9b1fc)
	allocs2fd9b1fc := new(cgoAllocMap)
	var cstructVersion_allocs *cgoAllocMap
	ref2fd9b1fc.structVersion, cstructVersion_allocs = (C.int)(x.StructVersion), cgoAllocsUnknown
	allocs2fd9b1fc.Borrow(cstructVersion_allocs)
	var c_type_allocs *cgoAllocMap
	ref2fd9b1fc._type, c_type_allocs = (C.PaHostApiTypeId)(x.Type), cgoAllocsUnknown
	allocs2fd9b1fc.Borrow(c_type_allocs)
	var cname_allocs *cgoAllocMap
	ref2fd9b1fc.name, cname_allocs = unpackPCharString(x.Name)
	allocs2fd9b1fc.Borrow(cname_allocs)
	var cdeviceCount_allocs *cgoAllocMap
	ref2fd9b1fc.deviceCount, cdeviceCount_allocs = (C.int)(x.DeviceCount), cgoAllocsUnknown
	allocs2fd9b1fc.Borrow(cdeviceCount_allocs)
	var cdefaultInputDevice_allocs *cgoAllocMap
	ref2fd9b1fc.defaultInputDevice, cdefaultInputDevice_allocs = (C.PaDeviceIndex)(x.DefaultInputDevice), cgoAllocsUnknown
	allocs2fd9b1fc.Borrow(cdefaultInputDevice_allocs)
	var cdefaultOutputDevice_allocs *cgoAllocMap
	ref2fd9b1fc.defaultOutputDevice, cdefaultOutputDevice_allocs = (C.PaDeviceIndex)(x.DefaultOutputDevice), cgoAllocsUnknown
	allocs2fd9b1fc.Borrow(cdefaultOutputDevice_allocs)
	x.ref2fd9b1fc = ref2fd9b1fc
	x.allocs2fd9b1fc = allocs2fd9b1fc
	return ref2fd9b1fc, allocs2fd9b1fc
}
func (x HostApiInfo) PassValue() (C.PaHostApiInfo, *cgoAllocMap) {
	if x.ref2fd9b1fc != nil {
		return *x.ref2fd9b1fc, nil
	}
	ref, allocs := x.PassRef()
	return *ref, allocs
}
func (x *HostApiInfo) Deref() {
	if x.ref2fd9b1fc == nil {
		return
	}
	x.StructVersion = (int32)(x.ref2fd9b1fc.structVersion)
	x.Type = (HostApiTypeId)(x.ref2fd9b1fc._type)
	x.Name = packPCharString(x.ref2fd9b1fc.name)
	x.DeviceCount = (int32)(x.ref2fd9b1fc.deviceCount)
	x.DefaultInputDevice = (DeviceIndex)(x.ref2fd9b1fc.defaultInputDevice)
	x.DefaultOutputDevice = (DeviceIndex)(x.ref2fd9b1fc.defaultOutputDevice)
}
func allocHostErrorInfoMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfHostErrorInfoValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfHostErrorInfoValue = unsafe.Sizeof([1]C.PaHostErrorInfo{})
func (x *HostErrorInfo) Ref() *C.PaHostErrorInfo {
	if x == nil {
		return nil
	}
	return x.ref5c7a77d7
}
func (x *HostErrorInfo) Free() {
	if x != nil && x.allocs5c7a77d7 != nil {
		x.allocs5c7a77d7.(*cgoAllocMap).Free()
		x.ref5c7a77d7 = nil
	}
}
func NewHostErrorInfoRef(ref unsafe.Pointer) *HostErrorInfo {
	if ref == nil {
		return nil
	}
	obj := new(HostErrorInfo)
	obj.ref5c7a77d7 = (*C.PaHostErrorInfo)(unsafe.Pointer(ref))
	return obj
}
func (x *HostErrorInfo) PassRef() (*C.PaHostErrorInfo, *cgoAllocMap) {
	if x == nil {
		return nil, nil
	} else if x.ref5c7a77d7 != nil {
		return x.ref5c7a77d7, nil
	}
	mem5c7a77d7 := allocHostErrorInfoMemory(1)
	ref5c7a77d7 := (*C.PaHostErrorInfo)(mem5c7a77d7)
	allocs5c7a77d7 := new(cgoAllocMap)
	var chostApiType_allocs *cgoAllocMap
	ref5c7a77d7.hostApiType, chostApiType_allocs = (C.PaHostApiTypeId)(x.HostApiType), cgoAllocsUnknown
	allocs5c7a77d7.Borrow(chostApiType_allocs)
	var cerrorCode_allocs *cgoAllocMap
	ref5c7a77d7.errorCode, cerrorCode_allocs = (C.long)(x.ErrorCode), cgoAllocsUnknown
	allocs5c7a77d7.Borrow(cerrorCode_allocs)
	var cerrorText_allocs *cgoAllocMap
	ref5c7a77d7.errorText, cerrorText_allocs = unpackPCharString(x.ErrorText)
	allocs5c7a77d7.Borrow(cerrorText_allocs)
	x.ref5c7a77d7 = ref5c7a77d7
	x.allocs5c7a77d7 = allocs5c7a77d7
	return ref5c7a77d7, allocs5c7a77d7
}
func (x HostErrorInfo) PassValue() (C.PaHostErrorInfo, *cgoAllocMap) {
	if x.ref5c7a77d7 != nil {
		return *x.ref5c7a77d7, nil
	}
	ref, allocs := x.PassRef()
	return *ref, allocs
}
func (x *HostErrorInfo) Deref() {
	if x.ref5c7a77d7 == nil {
		return
	}
	x.HostApiType = (HostApiTypeId)(x.ref5c7a77d7.hostApiType)
	x.ErrorCode = (int)(x.ref5c7a77d7.errorCode)
	x.ErrorText = packPCharString(x.ref5c7a77d7.errorText)
}