func (x *Seg) PassRef() *C.ps_seg_t {
	if x == nil {
		x = (*Seg)(allocSegMemory(1))
	}
	return (*C.ps_seg_t)(unsafe.Pointer(x))
}
PassRef returns a reference to C object as it is or allocates a new C object of this type.
package pocketsphinx
import "C"
import (
	"runtime"
	"sync"
	"unsafe"
)
func (x *Decoder) Ref() *C.ps_decoder_t {
	if x == nil {
		return nil
	}
	return (*C.ps_decoder_t)(unsafe.Pointer(x))
}
func (x *Decoder) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewDecoderRef(ref unsafe.Pointer) *Decoder {
	return (*Decoder)(ref)
}
func NewDecoder() *Decoder {
	return (*Decoder)(allocDecoderMemory(1))
}
func allocDecoderMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfDecoderValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfDecoderValue = unsafe.Sizeof([1]C.ps_decoder_t{})
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 (x *Decoder) PassRef() *C.ps_decoder_t {
	if x == nil {
		x = (*Decoder)(allocDecoderMemory(1))
	}
	return (*C.ps_decoder_t)(unsafe.Pointer(x))
}
func (x *Nbest) Ref() *C.ps_nbest_t {
	if x == nil {
		return nil
	}
	return (*C.ps_nbest_t)(unsafe.Pointer(x))
}
func (x *Nbest) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewNbestRef(ref unsafe.Pointer) *Nbest {
	return (*Nbest)(ref)
}
func NewNbest() *Nbest {
	return (*Nbest)(allocNbestMemory(1))
}
func allocNbestMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfNbestValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfNbestValue = unsafe.Sizeof([1]C.ps_nbest_t{})
func (x *Nbest) PassRef() *C.ps_nbest_t {
	if x == nil {
		x = (*Nbest)(allocNbestMemory(1))
	}
	return (*C.ps_nbest_t)(unsafe.Pointer(x))
}
func (x *Seg) Ref() *C.ps_seg_t {
	if x == nil {
		return nil
	}
	return (*C.ps_seg_t)(unsafe.Pointer(x))
}
func (x *Seg) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewSegRef(ref unsafe.Pointer) *Seg {
	return (*Seg)(ref)
}
func NewSeg() *Seg {
	return (*Seg)(allocSegMemory(1))
}
func allocSegMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfSegValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfSegValue = unsafe.Sizeof([1]C.ps_seg_t{})