slice2 := make([]int, 0) // slcie2 is empty slice var slice3 = make([]int, 2) // slice3 is zero slice if slice1 == nil { t.Log("slice1 is nil.") // 会输出这行 } if slice2 == nil { t.Log("slice2 is nil.") // 不会输出这行 } t.Log(slice3) // [0 0] ...
//第一部分,前置检查 //参数为slice类型,原silce,目的扩容大小 func growslice(et *_type, old slice, cap int) slice { //竞态检查 if raceenabled { callerpc := getcallerpc() racereadrangepc(old.array, uintptr(old.len*int(et.size)), callerpc, funcPC(growslice)) } if msanenabled { ms...
=0{lock(&sched.lock)gp := globrunqget(_p_,0)unlock(&sched.lock)ifgp !=nil{returngp,false,false}}...// Spinning Ms: steal work from other Ps./// Limit the number of spinning Ms to half the number of busy Ps.// This is necessary to prevent...
data := make([]byte, cap_sr) n, err := sr.Read(data) if err != nil { fmt.Printf("read to data failed, err: %s\n", err) return } fmt.Printf("read data size: %d, content: %s\n", n, data) }main函数结果read data size: 36, content: Today is monday, what a great start...
// If RootCAs is nil, TLS uses the host's root CA set. RootCAs *x509.CertPool // ServerName is used to verify the hostname on the returned // certificates unless InsecureSkipVerify is given. It is also included // in the client's handshake to support virtual hosting unless it is ...
runqhead uint32 runqtail uint32 runq [256]guintptr // runnext, if non-nil, is a runnable G that was ready'd by // the current G and should be run next instead of what's in // runq if there's time remaining in the running G's time // slice. It will inherit the time left...
// empty报告从c读取是否会阻塞(即通道为空)。它使用可变状态的单个原子读取。 func empty(c *hchan) bool { // c.dataqsiz is immutable. // c.dataqsiz是不可变的。 if c.dataqsiz == 0 { return atomic.Loadp(unsafe.Pointer(&c.sendq.first)) == nil } return atomic.Loaduint(&c.qcount)...
Go分为数据类型分为值类型和引用类型,其中值类型是 int、float、string、bool、struct和array,它们直接存储值,分配栈的内存空间,它们被函数调用完之后会释放;引用类型是 slice、map、chan和值类型对应的指针 它们存储是一个地址(或者理解为指针),指针指向内存中真正存储数据的首地址,内存通常在堆分配,通过GC回收。
1.使用值为 nil 的 slice、map会发生啥 允许对值为 nil 的 slice 添加元素,但对值为 nil 的 map 添加元素,则会造成运行时 panic。 // map 错误示例 func main() { var m map[string]int m["one"] = 1 // error: panic: assignment to entry in nil map ...
fix logger Args is empty slice 7年前 mapper.go support postgres sql quotes,fix #15 6年前 mapper_test.go Upgrade the major version to V2 6年前 model.go Update model.go 5年前 model_test.go support postgres sql quotes,fix #15 6年前 ...