Golang之sync.Pool对象池对象重用机制总结

本文详细介绍了Golang中的sync.Pool对象池机制,旨在减少GC负担并提供并发安全的对象重用。文章讨论了sync.Pool的结构、写入与读取流程、使用注意事项,以及在大规模Goroutine场景下可能遇到的瓶颈。核心优势在于对象复用,降低内存消耗和调度压力。
摘要由CSDN通过智能技术生成

文章来源于: https://gobea.cn/blog/detail/VrL2jbol.html

sync.Pool作用

对象重用机制,为了减少GC,sync.Pool是可伸缩的,并发安全的

两个结构体

type Pool struct {
   
    local     unsafe.Pointer // local fixed-size per-P pool, actual type is [P]poolLocal
    localSize uintptr        // size of the local array
  
    // New optionally specifies a function to generate
    // a value when Get would otherwise return nil.
    // It may not be changed concurrently with calls to Get.<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值