gtctl 源码分析

19 Mar 2024 | k8s, code

修订历史

  • 2024.03.19 创建笔记

目录结构

核心代码

其他细节

only store small buffers to avoid pointless allocation avoid keeping arbitrarily large buffers

func newBufferPool() *bufferPool {
	return &bufferPool{
		sync.Pool{
			New: func() interface{} {
				return new(bytes.Buffer)    // return pointer 类型
			},
		},
	}
}

func (b *bufferPool) Put(x *bytes.Buffer) {
	if x.Len() > 256 {
		return
	}
	x.Reset()
	b.Pool.Put(x)
}

func (l *logger) printf(format string, args ...interface{}) {
	buf := l.bufferPool.Get()
	fmt.Fprintf(buf, format, args...)
	l.writeBuffer(buf)
	l.bufferPool.Put(buf)
}

Older · View Archive (37)

收集一些 buzzword

Newer

goraft 源码分析