{"id":20388254,"url":"https://github.com/libp2p/go-buffer-pool","last_synced_at":"2025-04-14T15:54:42.921Z","repository":{"id":27697424,"uuid":"114931838","full_name":"libp2p/go-buffer-pool","owner":"libp2p","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-29T08:32:21.000Z","size":69,"stargazers_count":80,"open_issues_count":0,"forks_count":17,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-07T10:17:41.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libp2p.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-20T21:16:03.000Z","updated_at":"2025-03-28T13:07:28.000Z","dependencies_parsed_at":"2024-06-18T13:41:27.243Z","dependency_job_id":"729486cc-5572-47aa-91d6-a23bf5a4d55b","html_url":"https://github.com/libp2p/go-buffer-pool","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fgo-buffer-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fgo-buffer-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fgo-buffer-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fgo-buffer-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libp2p","download_url":"https://codeload.github.com/libp2p/go-buffer-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248912072,"owners_count":21182208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T03:08:18.217Z","updated_at":"2025-04-14T15:54:42.877Z","avatar_url":"https://github.com/libp2p.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"go-buffer-pool\n==================\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)\n[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](https://libp2p.io/)\n[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23libp2p)\n[![codecov](https://codecov.io/gh/libp2p/go-buffer-pool/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/go-buffer-pool)\n[![Travis CI](https://travis-ci.org/libp2p/go-buffer-pool.svg?branch=master)](https://travis-ci.org/libp2p/go-buffer-pool)\n[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)\n\n\u003e A variable size buffer pool for go.\n\n## Table of Contents\n\n- [About](#about)\n    - [Advantages over GC](#advantages-over-gc)\n    - [Disadvantages over GC:](#disadvantages-over-gc)\n- [Contribute](#contribute)\n- [License](#license)\n\n## About\n\nThis library provides:\n\n1. `BufferPool`: A pool for re-using byte slices of varied sizes. This pool will always return a slice with at least the size requested and a capacity up to the next power of two. Each size class is pooled independently which makes the `BufferPool` more space efficient than a plain `sync.Pool` when used in situations where data size may vary over an arbitrary range. \n2. `Buffer`: a buffer compatible with `bytes.Buffer` but backed by a `BufferPool`. Unlike `bytes.Buffer`, `Buffer` will automatically \"shrink\" on read, using the buffer pool to avoid causing too much work for the allocator. This is primarily useful for long lived buffers that usually sit empty.\n\n### Advantages over GC\n\n* Reduces Memory Usage:\n  * We don't have to wait for a GC to run before we can reuse memory. This is essential if you're repeatedly allocating large short-lived buffers.\n\n* Reduces CPU usage:\n  * It takes some load off of the GC (due to buffer reuse).\n  * We don't have to zero buffers (fewer wasteful memory writes).\n\n### Disadvantages over GC:\n\n* Can leak memory contents. Unlike the go GC, we *don't* zero memory.\n* All buffers have a capacity of a power of 2. This is fine if you either expect these buffers to be temporary or you need buffers of this size.\n* Requires that buffers be explicitly put back into the pool. This can lead to race conditions and memory corruption if the buffer is released while it's still in use.\n\n## Contribute\n\nPRs are welcome!\n\nSmall note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n## License\n\nMIT © Protocol Labs\nBSD © The Go Authors\n\n---\n\nThe last gx published version of this module was: 0.1.3: QmQDvJoB6aJWN3sjr3xsgXqKCXf4jU5zdMXpDMsBkYVNqa\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibp2p%2Fgo-buffer-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibp2p%2Fgo-buffer-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibp2p%2Fgo-buffer-pool/lists"}