func (mz *Memzone) Len() uintptr {
	return uintptr((*C.struct_rte_memzone)(mz).len)
}
Len returns length of the memzone.
package memzone
import "C"
import (
	"reflect"
	"unsafe"
	"github.com/yerden/go-dpdk/common"
)
type Memzone C.struct_rte_memzone
const (
	Page2Mb   uint = C.RTE_MEMZONE_2MB
	Page1Gb        = C.RTE_MEMZONE_1GB
	Page16Mb       = C.RTE_MEMZONE_16MB
	Page16Gb       = C.RTE_MEMZONE_16GB
	Page256Kb      = C.RTE_MEMZONE_256KB
	Page256Mb      = C.RTE_MEMZONE_256MB
	Page512Mb      = C.RTE_MEMZONE_512MB
	Page4Gb        = C.RTE_MEMZONE_4GB
	PageSizeHintOnly = C.RTE_MEMZONE_SIZE_HINT_ONLY
	PageIovaContig = C.RTE_MEMZONE_IOVA_CONTIG
)
type conf struct {
	cname   *C.char
	size    C.size_t
	socket  C.int
	flags   C.uint
	aligned *C.uint
	bound   *C.uint
}
type Option struct {
	f func(*conf)
}
func err(n ...interface{}) error {
	if len(n) == 0 {
		return common.RteErrno()
	}
	return common.IntToErr(n[0])
}
func OptSocket(socket uint) Option {
	return Option{func(rc *conf) {
		rc.socket = C.int(socket)
	}}
}
func OptFlag(flag uint) Option {
	return Option{func(rc *conf) {
		rc.flags |= C.uint(flag)
	}}
}
func OptAligned(align uint) Option {
	return Option{func(rc *conf) {
		rc.aligned = new(C.uint)
		*rc.aligned = C.uint(align)
	}}
}
func OptBounded(bound uint) Option {
	return Option{func(rc *conf) {
		rc.bound = new(C.uint)
		*rc.bound = C.uint(bound)
	}}
}
func doReserve(rc *conf) *C.struct_rte_memzone {
	switch {
	case rc.bound == nil && rc.aligned == nil:
		return C.rte_memzone_reserve(rc.cname, rc.size, rc.socket,
			rc.flags)
	case rc.bound == nil:
		return C.rte_memzone_reserve_aligned(rc.cname, rc.size, rc.socket,
			rc.flags, *rc.aligned)
	default:
		return C.rte_memzone_reserve_bounded(rc.cname, rc.size, rc.socket,
			rc.flags, *rc.aligned, *rc.bound)
	}
}
func Reserve(name string, size uintptr, opts ...Option) (*Memzone, error) {
	rc := &conf{
		socket: C.SOCKET_ID_ANY,
		size:   C.size_t(size),
		cname:  C.CString(name)}
	defer C.free(unsafe.Pointer(rc.cname))
	for i := range opts {
		opts[i].f(rc)
	}
	mz := (*Memzone)(doReserve(rc))
	if mz == nil {
		return nil, err()
	}
	return mz, nil
}
func Lookup(name string) (*Memzone, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	mz := (*Memzone)(C.rte_memzone_lookup(cname))
	if mz == nil {
		return nil, err()
	}
	return mz, nil
}
func (mz *Memzone) Free() error {
	return err(C.rte_memzone_free((*C.struct_rte_memzone)(mz)))
}
var (
	callbacks = common.NewRegistryArray()
)
func mzCb(mz *C.struct_rte_memzone, arg unsafe.Pointer) {
	cb := *(*common.ObjectID)(arg)
	fn := callbacks.Read(cb).(func(*Memzone))
	fn((*Memzone)(mz))
}
func Walk(fn func(*Memzone)) {
	cb := callbacks.Create(fn)
	C.rte_memzone_walk((*[0]byte)(C.mzCb), unsafe.Pointer(&cb))
	callbacks.Delete(cb)
}
func (mz *Memzone) Name() string {
	cmz := (*C.struct_rte_memzone)(mz)
	return C.GoString(&cmz.name[0])
}
func (mz *Memzone) Addr() unsafe.Pointer {
	addr := unsafe.Pointer(uintptr(unsafe.Pointer(mz)) + uintptr(C.OFF_MZ_ADDR))
	return *(*unsafe.Pointer)(addr)
}