remove cgo#5
Conversation
Go can call POSIX API without using cgo.
| "os" | ||
| "unsafe" | ||
|
|
||
| "golang.org/x/sys/unix" |
There was a problem hiding this comment.
Put this into glide.yaml and glide.lock.
There was a problem hiding this comment.
I added glide.yaml and glide.lock
|
@catatsuy Fix compilation error. |
cachectl/stat.go
Outdated
| pagesActive := activePages(fpath) | ||
| pagesActive, err := activePages(fpath) | ||
| if err != nil { | ||
| log.Fatalf("%v\n", err) |
There was a problem hiding this comment.
Use log.Printf() instead of log.Fatalf().
cachectl/activepages.go
Outdated
| if ret != 0 { | ||
| return 0, err | ||
| } | ||
| defer unix.Munmap(mmap) |
There was a problem hiding this comment.
Should munmap-call move to line after unix.Mmap()?
cachectl/activepages.go
Outdated
| result := 0 | ||
|
|
||
| for _, p := range pageinfo { | ||
| if p%2 == 1 { |
There was a problem hiding this comment.
The original C code is it. But I thought that this one was easier to understand.
I thought that it should be left to the optimization of the compiler, but should it match the original C code?
There was a problem hiding this comment.
Original code looks easier to understand. Because each entry of pageinfo is assumed that it is checked by the least significant bit. So using bit manipulation is more clear.
According to man mincore,
On return, the least significant bit of each byte will be set if the corresponding page is currently resident in memory, and be clear otherwise. (The settings of the other bits in each byte are undefined; these bits are reserved for possible later use.)
Go can call POSIX API without using cgo.