Golang
记录Go的学习过程,以及积累。
Blaze Jack
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
goland 技巧沉淀
关于配置读写的一种线程安全实现 type Config struct { Value string Expire int64 rwLock sync.RWMutex } func (config *Config) GetValue() (string, bool) { val := "" ok := false config.rwLock.RLock() if time.Now().Unix()-config.Expire < 5 { ok = true val = c.原创 2022-05-04 12:50:15 · 471 阅读 · 0 评论 -
Go获取当前协程信息
获取协程编号 func GetGid() (gid uint64) { b := make([]byte, 64) b = b[:runtime.Stack(b, false)] b = bytes.TrimPrefix(b, []byte("goroutine ")) b = b[:bytes.IndexByte(b, ' ')] n, err := strconv.ParseUint(string(b), 10, 64) if err != nil { panic(err) }原创 2022-04-03 23:43:43 · 3115 阅读 · 0 评论 -
GO G-P-M调度模型
总览图 名词解释 G: 表示goroutine,存储了goroutine的执行stack信息、goroutine状态以及goroutine的任务函数等;另外G对象是可以重用的。 P: 表示逻辑processor,P的数量决定了系统内最大可并行的G的数量(前提:系统的物理cpu核数>=P的数量);P的最大作用还是其拥有的各种G对象队列、链表、一些cache和状态。 M: M代表着真正的执行计算资源。在绑定有效的p后,进入schedule循环;而schedule循环的机制大致是从各种队列、p的原创 2022-03-19 21:21:28 · 648 阅读 · 0 评论 -
Golang怎么把string转int,int转string
Golang怎么把string转int,int转string原创 2021-12-25 22:30:58 · 1577 阅读 · 0 评论 -
Go语言压测函数
测试strconv.FormatBool 和fmt.Sprintf()的效率 func Benchmark_StrconvFormatBool(b *testing.B) { for i := 0; i < b.N; i++ { strconv.FormatBool(true) // => "true" strconv.FormatBool(false) // => "false" } } func Benchmark_FmtSprintfT(b *testing.B.原创 2021-12-20 14:32:46 · 411 阅读 · 0 评论
分享