1// 请求失败造成 panic2funcmain(){3resp,err:=http.Get("https://api.ipify.org?format=json")4defer resp.Body.Close()// resp 可能为 nil,不能读取 Body5iferr!=nil{6fmt.Println(err)7return8}910body,err:=ioutil.ReadAll(resp.Body)11checkError(err)1213fmt.Println(string(body))14}1516fu...
AI代码解释 // runtime/signal_unix.gofuncsetThreadCPUProfiler(hz int32){mp:=getg().m// 获取当前协程绑定的的线程M...spec:=new(itimerspec)spec.it_value.setNsec(1+int64(fastrandn(uint32(1e9/hz)))spec.it_interval.setNsec(1e9/int64(hz))// 设置间隔为 100000000/100 纳秒 = 10msvartim...
type slice struct { array unsafe.Pointer // 指向底层数组的指针lenint// 切片的长度capint// 切片的容量} Golang 官方文档声明:函数参数传参只有值传递一种方式。值传递方式会在调用函数时将实际参数拷贝一份传递到函数中,slice 参数被传递到函数中时,其 array、len 以及 cap 都被复制了一份,因此函数...
to avoid a bounds check// key 是指针ift.indirectkey {// 将原 key(是指针)复制到新位置*(*unsafe.Pointer)(dst.k) = k2// copy pointer}else{// 将原 key(是值)复制到新位置typedmemmove(t.key, dst.k, k)// copy value}//value同上ift.indirectvalue { ...
map 的 key 为从 session 中获取的 RemoteAddress 即 Transaction Coordinator 的地址,value 为 session。这样,Client 端就可以通过 map 中的一个 session 来向 Transaction Coordinator 注册 Transaction Manager 和 Resource Manager 了。具体代码见 getty_client_session_manager.go。 Transaction Manager 和 Resource ...
不同之处在于,使用 delete 删除 key时,并没有真的将保存 key-value的内存清空,而是直接将 tophash[i]置为特定的状态标记(emptyOne 或 emptyRest),以表明该位置是空的。当然,如果 key 或 value 中含有指针,还需要将指针置为 nil,以保证删除的key 和 value 可以被 GC 回收掉。 func mapdelete(t *maptype...
func (s *state) append(n *Node, inplace bool) *ssa.Value { ... } 其中,中间代码生成阶段的state.append方法,是我们重点关注的地方。入参inplace代表返回值是否覆盖原变量。如果为false,展开逻辑如下(注意:以下代码只是为了方便理解的伪代码,并不是state.append中实际的代码)。同时,小菜刀注意到如果写成app...
所以和上面一样第一个slot就是checkmark heapBitsSetType(uintptr(x), size, dataSize, typ) if dataSize > typ.size { // Array allocation. If there are any // pointers, GC has to scan to the last // element. if typ.ptrdata != 0 { scanSize = dataSize - typ.size + typ.ptrdata } ...
Go 1.2 adds new syntax to allow a slicing operation to specify the capacity as well as the length. A second colon introduces the capacity value, which must be less than or equal to the capacity of the source slice or array, adjusted for the origin. ...
(14)checkBucket:因为扩容流程的存在,需要额外检查的桶. 8.2 mapiterinit map 遍历流程开始时,首先会走进 runtime/map.go 的 mapiterinit() 方法当中,此时会对创建 map 迭代器 hiter,并且通过取随机数的方式,决定遍历的起始桶号,以及起始 key-value 对索引号. func mapiterinit(t *maptype, h *hmap, it...