race

Posted by 夏泽民

比如一个全局变量,如果没有加上锁,我们写一个比较庞大的项目下来,就根本不知道这个变量是不是会引起多个goroutine竞争。 package main



make new 的区别

Posted by 夏泽民

二者都在堆上分配内存,但是它们的行为不同,适用于不同的类型。



interface

Posted by 夏泽民

golang中的接口分为带方法的接口和空接口。 带方法的接口在底层用iface表示,空接口的底层则是eface表示。 //runtime/runtime2.go



flame graph

Posted by 夏泽民

安装go-torch go get github.com/uber/go-torch 安装 FlameGraph cd $WORK_PATH && git clone https://github.com/brendangregg/FlameGraph.git export PATH=$PATH:$WORK_PATH/FlameGraph-master 安装graphviz yum install graphviz(CentOS, Redhat) package main

import ( “net/http” “net/http/pprof” )

func main() { // 主函数中添加 go func() { http.HandleFunc(“/debug/pprof/block”, pprof.Index) http.HandleFunc(“/debug/pprof/goroutine”, pprof.Index) http.HandleFunc(“/debug/pprof/heap”, pprof.Index) http.HandleFunc(“/debug/pprof/threadcreate”, pprof.Index)

    http.ListenAndServe("0.0.0.0:8888", nil)
}()
 
var finishWaiter chan int
<-finishWaiter }


defer

Posted by 夏泽民

defer的行为规则,只有三条 规则一:延迟函数的参数在defer语句出现时就已经确定下来了 官方给出一个例子,如下所示:



Search

Popular posts

Anything in here will be replaced on browsers that support the canvas element

Recent posts

This blog is maintained by 夏泽民

Get in touch with me at 465474307@qq.com

Subscribe to our mailing list

* indicates required