2,190
社区成员
发帖
与我相关
我的任务
分享
package main
import (
"fmt"
"time"
)
func exec() {
go exe()
go exe()
go exe()
}
func main() {
exec()
time.Sleep(3600 * time.Second)
}
type mydata struct {
cb []byte
str string
}
func exe() {
var mq = make(chan *mydata, 1024)
for i := 0; i < 1024; i++ {
p := new(mydata)
p.cb = make([]byte, 1024*1024*5)
p.str = fmt.Sprintf("%d", i)
mq <- p
}
close(mq)
for p := range mq {
fmt.Println(p.str)
}
fmt.Println("退出exe ", len(mq))
}
package main
import (
"fmt"
"time"
)
func main() {
sliceLength := 1 << 10
// 1MB
buffLength := 1 << 20
datas := make([][]byte, sliceLength)
for i := 0; i < sliceLength; i++ {
buff := make([]byte, buffLength)
for i := 0; i < buffLength; i++ {
buff[i] = 'G'
}
datas[i] = buff
}
fmt.Println("Cancel...")
<-time.After(time.Hour)
}
package main
import (
"fmt"
"time"
"github.com/glycerine/offheap"
)
func main() {
sliceLength := 1 << 10
// 1MB
buffLength := 1 << 20
datas := make([][]byte, sliceLength)
freeList := make([]*offheap.MmapMalloc, sliceLength)
// Malloc
for i := 0; i < sliceLength; i++ {
mmap := offheap.Malloc(int64(buffLength), "")
buff := mmap.Mem
for i := 0; i < buffLength; i++ {
buff[i] = 'G'
}
datas[i] = buff
freeList[i] = mmap
}
// free
for _, v := range freeList {
v.Free()
}
fmt.Println("Cancel...")
<-time.After(time.Hour)
}