58 lines
722 B
Go
58 lines
722 B
Go
package gotoc
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
"reflect"
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
/*
|
|
#include "../../../../../Include/sigar.h"
|
|
|
|
*/
|
|
import "C"
|
|
|
|
var sigar *C.sigar_t=nil
|
|
func GetSigarHandle()*C.sigar_t{
|
|
|
|
if(sigar!=nil){
|
|
return sigar
|
|
}
|
|
sigar=new (C.sigar_t)
|
|
ret:=C.sigar_open(&sigar)
|
|
if(ret!=C.SIGAR_OK){
|
|
return nil
|
|
}
|
|
return sigar
|
|
|
|
}
|
|
|
|
func CloseSigarHandle(sigar *C.sigar_t) {
|
|
|
|
if(sigar!=nil){
|
|
C.sigar_close(sigar)
|
|
return
|
|
}
|
|
fmt.Println("Trying to close a nil handel, ignoring")
|
|
}
|
|
|
|
|
|
func GetGoSlice(number int, pointer unsafe.Pointer ) reflect.SliceHeader{
|
|
var length int=int(number)
|
|
|
|
|
|
cObj := reflect.SliceHeader{
|
|
Data: uintptr(pointer),
|
|
Len: length,
|
|
Cap: length,
|
|
}
|
|
|
|
|
|
|
|
|
|
return cObj
|
|
|
|
|
|
} |