本文整理匯總了Golang中C.kcfree函數的典型用法代碼示例。如果您正苦於以下問題:Golang kcfree函數的具體用法?Golang kcfree怎麽用?Golang kcfree使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了kcfree函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Iter
func (self *KcDb) Iter(fun func(string, Getter) bool) {
cur := C.kcdbcursor(self.cdb)
C.kccurjump(cur)
var kSize, vSize C.size_t
var vBuff, kBuff *C.char
var ret bool
for {
kBuff = C.kccurget(cur, &kSize, &vBuff, &vSize, kcTrue)
if kBuff == nil {
C.kcfree(unsafe.Pointer(kBuff))
break
}
key := string(C.GoBytes(unsafe.Pointer(kBuff), C.int(kSize)))
value := C.GoBytes(unsafe.Pointer(vBuff), C.int(vSize))
r := bytes.NewReader(value)
ret = fun(key, func(e interface{}) error {
return decode(r, e)
})
C.kcfree(unsafe.Pointer(kBuff))
if ret == false {
break
}
}
C.kccurdel(cur)
}
示例2: Status
func (kc *KCDB) Status() (status string, err error) {
cstatus := C.kcdbstatus(kc.db)
if cstatus == nil {
err = kc.error()
}
status = C.GoString(cstatus)
C.kcfree(unsafe.Pointer(cstatus))
return
}
示例3: Path
func (kc *KCDB) Path() (path string, err error) {
cpath := C.kcdbpath(kc.db)
defer C.kcfree(unsafe.Pointer(cpath))
path = C.GoString(cpath)
if path == "" {
err = kc.error()
}
return
}
示例4: Get
func (kc *KCDB) Get(key []byte) (value []byte, err error) {
ckey := (*C.char)(unsafe.Pointer(&key[0]))
var vlen C.size_t
cval := C.kcdbget(kc.db, ckey, C.size_t(len(key)), &vlen)
if cval == nil {
err = kc.error()
} else {
value = make([]byte, int(vlen))
C.memcpy(unsafe.Pointer(&value[0]), unsafe.Pointer(cval), vlen)
C.kcfree(unsafe.Pointer(cval))
}
return
}
示例5: MatchRegex
func (kc *KCDB) MatchRegex(regex string, max int) (matches [][]byte, err error) {
cregex := C.CString(regex)
strarray := make([]*C.char, max)
count := C.kcdbmatchregex(kc.db, cregex, &strarray[0], C.size_t(max))
if count == -1 {
matches = nil
err = kc.error()
} else {
matches = make([][]byte, count)
for i := int64(0); i < int64(count); i++ {
matches[i] = []byte(C.GoString(strarray[i]))
C.kcfree(unsafe.Pointer(strarray[i]))
}
}
C.free(unsafe.Pointer(cregex))
return
}
示例6: GetValue
func (kcc *KCCUR) GetValue(advance bool) (v []byte, err error) {
var vsiz C.size_t
var cadvance C.int32_t
if advance {
cadvance = 1
} else {
cadvance = 0
}
vp := C.kccurgetvalue(kcc.cur, &vsiz, cadvance)
if vp != nil {
v = make([]byte, vsiz)
C.memcpy(unsafe.Pointer(&v[0]), unsafe.Pointer(vp), vsiz)
C.kcfree(unsafe.Pointer(vp))
} else {
err = kcc.error()
}
return
}
示例7: GetKey
func (kcc *KCCUR) GetKey(advance bool) (k []byte, err error) {
var ksiz C.size_t
var cadvance C.int32_t
if advance {
cadvance = 1
} else {
cadvance = 0
}
kp := C.kccurgetkey(kcc.cur, &ksiz, cadvance)
if kp != nil {
k = make([]byte, ksiz)
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), ksiz)
C.kcfree(unsafe.Pointer(kp))
} else {
err = kcc.error()
}
return
}
示例8: Get
func (self *KcDb) Get(key string, obj interface{}) error {
var b []byte
var err error
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
var vSize C.size_t
vBuf := C.kcdbget(self.cdb, cKey, C.size_t(len(key)), &vSize)
if vBuf == nil {
return errors.New(fmt.Sprintf("get: %s", key))
}
defer C.kcfree(unsafe.Pointer(vBuf))
b = C.GoBytes(unsafe.Pointer(vBuf), C.int(vSize))
r := bytes.NewReader(b)
err = decode(r, obj)
if err != nil {
return err
}
return nil
}
示例9: Get
func (kcc *KCCUR) Get(advance bool) (k, v []byte, err os.Error) {
var ksiz, vsiz C.size_t
var vp *C.char
var cadvance C.int32_t
if advance {
cadvance = 1
} else {
cadvance = 0
}
kp := C.kccurget(kcc.cur, &ksiz, &vp, &vsiz, cadvance)
if kp != nil {
k = make([]byte, ksiz)
C.memcpy(unsafe.Pointer(&k[0]), unsafe.Pointer(kp), ksiz)
v = make([]byte, vsiz)
C.memcpy(unsafe.Pointer(&v[0]), unsafe.Pointer(vp), vsiz)
C.kcfree(unsafe.Pointer(kp))
} else {
err = kcc.error()
}
return
}