func (x *LatlinkIter) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
Free cleanups the referenced memory using C free.
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{})
func (x *Seg) PassRef() *C.ps_seg_t {
	if x == nil {
		x = (*Seg)(allocSegMemory(1))
	}
	return (*C.ps_seg_t)(unsafe.Pointer(x))
}
func (x *File) Ref() *C.FILE {
	if x == nil {
		return nil
	}
	return (*C.FILE)(unsafe.Pointer(x))
}
func (x *File) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewFileRef(ref unsafe.Pointer) *File {
	return (*File)(ref)
}
func NewFile() *File {
	return (*File)(allocFileMemory(1))
}
func allocFileMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfFileValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfFileValue = unsafe.Sizeof([1]C.FILE{})
func (x *File) PassRef() *C.FILE {
	if x == nil {
		x = (*File)(allocFileMemory(1))
	}
	return (*C.FILE)(unsafe.Pointer(x))
}
func allocArgMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfArgValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfArgValue = unsafe.Sizeof([1]C.arg_t{})
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 *Arg) Ref() *C.arg_t {
	if x == nil {
		return nil
	}
	return x.ref8495e8ec
}
func (x *Arg) Free() {
	if x != nil && x.allocs8495e8ec != nil {
		x.allocs8495e8ec.(*cgoAllocMap).Free()
		x.ref8495e8ec = nil
	}
}
func NewArgRef(ref unsafe.Pointer) *Arg {
	if ref == nil {
		return nil
	}
	obj := new(Arg)
	obj.ref8495e8ec = (*C.arg_t)(unsafe.Pointer(ref))
	return obj
}
func (x *Arg) PassRef() (*C.arg_t, *cgoAllocMap) {
	if x == nil {
		return nil, nil
	} else if x.ref8495e8ec != nil {
		return x.ref8495e8ec, nil
	}
	mem8495e8ec := allocArgMemory(1)
	ref8495e8ec := (*C.arg_t)(mem8495e8ec)
	allocs8495e8ec := new(cgoAllocMap)
	allocs8495e8ec.Add(mem8495e8ec)
	var cname_allocs *cgoAllocMap
	ref8495e8ec.name, cname_allocs = unpackPCharString(x.Name)
	allocs8495e8ec.Borrow(cname_allocs)
	var c_type_allocs *cgoAllocMap
	ref8495e8ec._type, c_type_allocs = (C.int)(x.Type), cgoAllocsUnknown
	allocs8495e8ec.Borrow(c_type_allocs)
	var cdeflt_allocs *cgoAllocMap
	ref8495e8ec.deflt, cdeflt_allocs = unpackPCharString(x.Deflt)
	allocs8495e8ec.Borrow(cdeflt_allocs)
	var cdoc_allocs *cgoAllocMap
	ref8495e8ec.doc, cdoc_allocs = unpackPCharString(x.Doc)
	allocs8495e8ec.Borrow(cdoc_allocs)
	x.ref8495e8ec = ref8495e8ec
	x.allocs8495e8ec = allocs8495e8ec
	return ref8495e8ec, allocs8495e8ec
}
func (x Arg) PassValue() (C.arg_t, *cgoAllocMap) {
	if x.ref8495e8ec != nil {
		return *x.ref8495e8ec, nil
	}
	ref, allocs := x.PassRef()
	return *ref, allocs
}
func (x *Arg) Deref() {
	if x.ref8495e8ec == nil {
		return
	}
	x.Name = packPCharString(x.ref8495e8ec.name)
	x.Type = (int32)(x.ref8495e8ec._type)
	x.Deflt = packPCharString(x.ref8495e8ec.deflt)
	x.Doc = packPCharString(x.ref8495e8ec.doc)
}
func (x *CommandLn) Ref() *C.cmd_ln_t {
	if x == nil {
		return nil
	}
	return (*C.cmd_ln_t)(unsafe.Pointer(x))
}
func (x *CommandLn) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewCommandLnRef(ref unsafe.Pointer) *CommandLn {
	return (*CommandLn)(ref)
}
func NewCommandLn() *CommandLn {
	return (*CommandLn)(allocCommandLnMemory(1))
}
func allocCommandLnMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfCommandLnValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfCommandLnValue = unsafe.Sizeof([1]C.cmd_ln_t{})
func (x *CommandLn) PassRef() *C.cmd_ln_t {
	if x == nil {
		x = (*CommandLn)(allocCommandLnMemory(1))
	}
	return (*C.cmd_ln_t)(unsafe.Pointer(x))
}
func (x *Logmath) Ref() *C.logmath_t {
	if x == nil {
		return nil
	}
	return (*C.logmath_t)(unsafe.Pointer(x))
}
func (x *Logmath) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewLogmathRef(ref unsafe.Pointer) *Logmath {
	return (*Logmath)(ref)
}
func NewLogmath() *Logmath {
	return (*Logmath)(allocLogmathMemory(1))
}
func allocLogmathMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfLogmathValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfLogmathValue = unsafe.Sizeof([1]C.logmath_t{})
func (x *Logmath) PassRef() *C.logmath_t {
	if x == nil {
		x = (*Logmath)(allocLogmathMemory(1))
	}
	return (*C.logmath_t)(unsafe.Pointer(x))
}
func (x *Fe) Ref() *C.fe_t {
	if x == nil {
		return nil
	}
	return (*C.fe_t)(unsafe.Pointer(x))
}
func (x *Fe) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewFeRef(ref unsafe.Pointer) *Fe {
	return (*Fe)(ref)
}
func NewFe() *Fe {
	return (*Fe)(allocFeMemory(1))
}
func allocFeMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfFeValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfFeValue = unsafe.Sizeof([1]C.fe_t{})
func (x *Fe) PassRef() *C.fe_t {
	if x == nil {
		x = (*Fe)(allocFeMemory(1))
	}
	return (*C.fe_t)(unsafe.Pointer(x))
}
func (x *Feat) Ref() *C.feat_t {
	if x == nil {
		return nil
	}
	return (*C.feat_t)(unsafe.Pointer(x))
}
func (x *Feat) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewFeatRef(ref unsafe.Pointer) *Feat {
	return (*Feat)(ref)
}
func NewFeat() *Feat {
	return (*Feat)(allocFeatMemory(1))
}
func allocFeatMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfFeatValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfFeatValue = unsafe.Sizeof([1]C.feat_t{})
func (x *Feat) PassRef() *C.feat_t {
	if x == nil {
		x = (*Feat)(allocFeatMemory(1))
	}
	return (*C.feat_t)(unsafe.Pointer(x))
}
func (x *Lattice) Ref() *C.ps_lattice_t {
	if x == nil {
		return nil
	}
	return (*C.ps_lattice_t)(unsafe.Pointer(x))
}
func (x *Lattice) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewLatticeRef(ref unsafe.Pointer) *Lattice {
	return (*Lattice)(ref)
}
func NewLattice() *Lattice {
	return (*Lattice)(allocLatticeMemory(1))
}
func allocLatticeMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfLatticeValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfLatticeValue = unsafe.Sizeof([1]C.ps_lattice_t{})
func (x *Lattice) PassRef() *C.ps_lattice_t {
	if x == nil {
		x = (*Lattice)(allocLatticeMemory(1))
	}
	return (*C.ps_lattice_t)(unsafe.Pointer(x))
}
func (x *Latnode) Ref() *C.ps_latnode_t {
	if x == nil {
		return nil
	}
	return (*C.ps_latnode_t)(unsafe.Pointer(x))
}
func (x *Latnode) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewLatnodeRef(ref unsafe.Pointer) *Latnode {
	return (*Latnode)(ref)
}
func NewLatnode() *Latnode {
	return (*Latnode)(allocLatnodeMemory(1))
}
func allocLatnodeMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfLatnodeValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfLatnodeValue = unsafe.Sizeof([1]C.ps_latnode_t{})
func (x *Latnode) PassRef() *C.ps_latnode_t {
	if x == nil {
		x = (*Latnode)(allocLatnodeMemory(1))
	}
	return (*C.ps_latnode_t)(unsafe.Pointer(x))
}
func (x *LatnodeIter) Ref() *C.ps_latnode_iter_t {
	if x == nil {
		return nil
	}
	return (*C.ps_latnode_iter_t)(unsafe.Pointer(x))
}
func (x *LatnodeIter) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewLatnodeIterRef(ref unsafe.Pointer) *LatnodeIter {
	return (*LatnodeIter)(ref)
}
func NewLatnodeIter() *LatnodeIter {
	return (*LatnodeIter)(allocLatnodeIterMemory(1))
}
func allocLatnodeIterMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfLatnodeIterValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfLatnodeIterValue = unsafe.Sizeof([1]C.ps_latnode_iter_t{})
func (x *LatnodeIter) PassRef() *C.ps_latnode_iter_t {
	if x == nil {
		x = (*LatnodeIter)(allocLatnodeIterMemory(1))
	}
	return (*C.ps_latnode_iter_t)(unsafe.Pointer(x))
}
func (x *Latlink) Ref() *C.ps_latlink_t {
	if x == nil {
		return nil
	}
	return (*C.ps_latlink_t)(unsafe.Pointer(x))
}
func (x *Latlink) Free() {
	if x != nil {
		C.free(unsafe.Pointer(x))
	}
}
func NewLatlinkRef(ref unsafe.Pointer) *Latlink {
	return (*Latlink)(ref)
}
func NewLatlink() *Latlink {
	return (*Latlink)(allocLatlinkMemory(1))
}
func allocLatlinkMemory(n int) unsafe.Pointer {
	mem, err := C.calloc(C.size_t(n), (C.size_t)(sizeOfLatlinkValue))
	if err != nil {
		panic("memory alloc error: " + err.Error())
	}
	return mem
}
const sizeOfLatlinkValue = unsafe.Sizeof([1]C.ps_latlink_t{})
func (x *Latlink) PassRef() *C.ps_latlink_t {
	if x == nil {
		x = (*Latlink)(allocLatlinkMemory(1))
	}
	return (*C.ps_latlink_t)(unsafe.Pointer(x))
}
func (x *LatlinkIter) Ref() *C.ps_latlink_iter_t {
	if x == nil {
		return nil
	}
	return (*C.ps_latlink_iter_t)(unsafe.Pointer(x))
}