Skip to content

bigcache ringbuffer 扩容的一点疑问 #179

@microyahoo

Description

@microyahoo

https://github.com/rfyiamcool/notes/blob/main/golang_bigcache_cache.md
您好,感谢您的分享,很受用。但是在看代码和您的分享过程中发现对于 ringbuffer 扩容场景有点对不上,以下是我个人分析,如有错误还请批评指正,谢谢!

文章中提到第二种扩容场景,如下图所示:
202304051930272

但是看代码对于 q.head > q.tail 的场景,实现应该是 oldArray 先整体拷贝到新的 array 中,然后填充 q.head-q.tail 个空字符 slice,主要是为了将 tail 指针移动到跟 head 保持一致,如下图所示:
bigcache drawio

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions