funny / binary Goto Github PK
View Code? Open in Web Editor NEWbinary data operation utilities for Go
License: Do What The F*ck You Want To Public License
binary data operation utilities for Go
License: Do What The F*ck You Want To Public License
我觉得现在这个内存池设计得不好,以link里的codec_packet.go
为例,里面的Encoder
和Decoder
会尽量复用[]byte
,只有在序列化消息容量不够或者是接收包的时候容量不够时才会make一个新的,所以[]byte
的创建频率是不高的。
现在的BufferPool比较符合的应用场景是频繁的创建销毁[]byte
的场景,跟上面这种应用场景不符,如果长久持有[]byte
,BufferPool里面的[]byte
很快就被耗尽了并且不会被回收利用。
所以codec_packet.go
里面用sync.Pool
更合适,在频繁创建销毁[]byte
的时候sync.Pool
会尽量重用对象,在频率低的时候对象又会被释放。
对于sync.Pool
不能精确分类[]byte
的问题,可以用多个sync.Pool
来实现。
func (writer *Writer) Flush() error {
if flusher, ok := writer.w.(FlushWriter); writer.err != nil && ok {
writer.err = flusher.Flush()
}
return writer.err
}
上面的代码是不是应该修改为
func (writer *Writer) Flush() error {
if flusher, ok := writer.w.(FlushWriter); writer.err == nil && ok {
writer.err = flusher.Flush()
}
return writer.err
}
我是新手,如果提错了,请谅解
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.