type Counter struct { mu sync.Mutex counters map[string]int } func (c Counter) Increment(name string) { c.mu.Lock() defer c.mu.Unlock() c.counters[name]++ } func NewCounter() Counter { return Counter{counters: map[string]int{}} } func main() { counter := NewCounter() go counte...
💪 Helper Utils(700+): int, byte, string, array/slice, map, struct, dump, convert/format, error, web/http, cli/flag, OS/ENV, filesystem, system, test/assert, time and more. Go 常用的一些工具函数:数字,字符串,数组,Map,结构体,反射,文本,文件,错误
深入理解Go调度原理和实现 本文深入分析Go调度原理和实现,全文包含的主要内容有:Go程序是怎么运行起来的,经历了哪些流程,调度G的策略和时机,程序是如何在执行runtime代码与用户代码之间来回切换的。文章内容很长,感兴趣的同学可以收藏慢慢看。本文中分析的代码是Go1.14版本,涉及到的文件都在runtime包下。 对于编译性语...
f := findfunc(fn.fn) stkmap := (*stackmap)(funcdata(f, _FUNCDATA_ArgsPointerMaps)) // We're in the prologue, so it's always stack map index 0. bv := stackmapdata(stkmap, 0) bulkBarrierBitmap(spArg, spArg, uintptr(narg), 0, bv.bytedata) } } memclrNoHeapPointers(unsafe.Po...
Go1.20的runtime.heapArena和Go1.18之前的有不同的是bitmap的一个比特位表示一个word字,而不是一个字节Byte,在Linux 64系统中,一个heapArena管理的内存大小是64MB,那么用一个比特位指代一个字长,则需要64MB/(8*64)=128K个Bit,而且一个占有8Bword的对象是否有指针是用另一个字段noMorePtrs来记录的,而不是都在...
批量插入,FindInBatches,Find/Create with Map,使用 SQL 表达式、Context Valuer 进行 CRUD SQL 构建...
package main import ( "log" ) type Exception struct { Id int // exception id Msg string // exception msg } type TryStruct struct { catches map[int]ExceptionHandler try func() } func Try(tryHandler func()) *TryStruct { tryStruct := TryStruct{ catches: make(map[int]ExceptionHandler),...
Fast, efficient, and scalable distributed map/reduce system, DAG execution, in memory or on disk, written in pure Go, runs standalone or distributedly. - chrislusf/gleam
var a map[string] int var a chan int var a func(string) int var a error // error 是接口 根据值自行判定变量类型 例:var d = true (这点就有点像js了) 省略var, 注意 := 左侧如果没有声明新的变量,就产生编译错误,格式:v_name := value 例:f := “Ru...
func(ocr *OCRSystem)PredictDirImages(dirnamestring)map[string][]OCRText dirname图片文件夹的目录,默认会预测改目录下所有jpg和png图片,并返回每张图的预测结果。 OCR Server func(ocr *OCRSystem)StartServer(portstring) 开启OCR预测Server,开启后,使用post请求上传需要识别的图片至http://$ip:$port/ocr即可直...