{"id":18821634,"url":"https://github.com/octu0/cgobytepool","last_synced_at":"2025-07-29T07:34:50.358Z","repository":{"id":79220520,"uuid":"600778544","full_name":"octu0/cgobytepool","owner":"octu0","description":"Shared byte pool implementation between C and Go(cgo)","archived":false,"fork":false,"pushed_at":"2023-03-23T03:37:55.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T10:51:57.327Z","etag":null,"topics":["buffer-pool","cgo","golang","pool","shared-memory"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/octu0/cgobytepool","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/octu0.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,"zenodo":null}},"created_at":"2023-02-12T15:20:36.000Z","updated_at":"2024-08-29T01:40:04.000Z","dependencies_parsed_at":"2023-05-15T09:00:26.509Z","dependency_job_id":null,"html_url":"https://github.com/octu0/cgobytepool","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/octu0/cgobytepool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fcgobytepool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fcgobytepool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fcgobytepool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fcgobytepool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/octu0","download_url":"https://codeload.github.com/octu0/cgobytepool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fcgobytepool/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267646388,"owners_count":24121000,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["buffer-pool","cgo","golang","pool","shared-memory"],"created_at":"2024-11-08T00:44:59.022Z","updated_at":"2025-07-29T07:34:50.345Z","avatar_url":"https://github.com/octu0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cgobytepool`\n\n[![MIT License](https://img.shields.io/github/license/octu0/cgobytepool)](https://github.com/octu0/cgobytepool/blob/master/LICENSE)\n[![GoDoc](https://godoc.org/github.com/octu0/cgobytepool?status.svg)](https://godoc.org/github.com/octu0/cgobytepool)\n[![Go Report Card](https://goreportcard.com/badge/github.com/octu0/cgobytepool)](https://goreportcard.com/report/github.com/octu0/cgobytepool)\n[![Releases](https://img.shields.io/github/v/release/octu0/cgobytepool)](https://github.com/octu0/cgobytepool/releases)\n\nShared byte pool implementation between C and Go(cgo)  \n`unsigned char*` in C / `[]byte` in Go (convertible using [unsafe.Slice](https://pkg.go.dev/unsafe#Slice) or [reflect.SliceHeader](https://pkg.go.dev/reflect#SliceHeader))  \nthis pool shares using [cgo.Handle](https://pkg.go.dev/runtime/cgo#Handle)\n\n# How to use\n\nNeed to declare `extern` in C and declare `export` in Go\n\n```go\n/*\n#include \u003cstdlib.h\u003e\n\nextern void *bytepool_get(void *context, size_t size);\nextern void bytepool_put(void *context, void *data, size_t size);\nextern void bytepool_free(void *context);\n\nstatic void ExampleCgo(void *ctx) {\n  unsigned char *data = (unsigned char*) bytepool_get(ctx, 100);\n  do_something(data);\n  bytepool_put(ctx, data, 100);\n  bytepool_free(ctx);\n}\n*/\nimport \"C\"\n\nimport (\n\t\"unsafe\"\n\n\t\"github.com/octu0/cgobytepool\"\n)\n\n//export bytepool_get\nfunc bytepool_get(ctx unsafe.Pointer, size C.size_t) unsafe.Pointer {\n\treturn cgobytepool.HandlePoolGet(ctx, int(size))\n}\n\n//export bytepool_put\nfunc bytepool_put(ctx unsafe.Pointer, data unsafe.Pointer, size C.size_t) {\n\tcgobytepool.HandlePoolPut(ctx, data, int(size))\n}\n\n//export bytepool_free\nfunc bytepool_free(ctx unsafe.Pointer) {\n\tcgobytepool.HandlePoolFree(ctx)\n}\n\nfunc ExampleGo(p cgobytepool.Pool) {\n\tptr := p.Get(100)\n\tdefer p.Put(ptr, 100)\n\n\tdata := unsafe.Slice((*byte)(ptr), 100)\n\tprintln(len(data)) // =\u003e 100\n\tprintln(cap(data)) // =\u003e 100\n\n\tdoSomething(data)\n}\n\nfunc main() {\n\tp := cgobytepool.NewPool(\n\t\tcgobytepool.DefaultMemoryAlignmentFunc,\n\t\tcgobytepool.WithPoolSize(1000, 16*1024),\n\t\tcgobytepool.WithPoolSize(1000, 4*1024),\n\t\tcgobytepool.WithPoolSize(1000, 512),\n\t)\n\n\tExampleGo(p)\n\n\th := cgobytepool.CgoHandle(p)\n\tC.ExampleCgo(unsafe.Pointer(\u0026h))\n}\n```\n\n# Benchmark\n\n```\ngoos: darwin\ngoarch: amd64\npkg: github.com/octu0/cgobytepool/benchmark\ncpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz\nBenchmarkCgoBytePool\nBenchmarkCgoBytePool/cgohandle\nBenchmarkCgoBytePool/cgohandle-8         \t              218674\t        4764 ns/op\t   21209 B/op\t      10 allocs/op\nBenchmarkCgoBytePool/cgohandle_reflect\nBenchmarkCgoBytePool/cgohandle_reflect-8 \t              572455\t        2039 ns/op\t     198 B/op\t       6 allocs/op\nBenchmarkCgoBytePool/cgohandle_array\nBenchmarkCgoBytePool/cgohandle_array-8   \t              594552\t        2082 ns/op\t     198 B/op\t       6 allocs/op\nBenchmarkCgoBytePool/cgohandle_unsafeslice\nBenchmarkCgoBytePool/cgohandle_unsafeslice-8         \t  580590\t        2040 ns/op\t     198 B/op\t       6 allocs/op\nBenchmarkCgoBytePool/malloc\nBenchmarkCgoBytePool/malloc-8                        \t  433221\t        3001 ns/op\t   21008 B/op\t       4 allocs/op\nBenchmarkCgoBytePool/malloc_reflect\nBenchmarkCgoBytePool/malloc_reflect-8                \t10844132\t       115.3 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkCgoBytePool/malloc_reflect2\nBenchmarkCgoBytePool/malloc_reflect2-8               \t 9369612\t       129.3 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkCgoBytePool/malloc_unsafeslice\nBenchmarkCgoBytePool/malloc_unsafeslice-8            \t 8921526\t       133.3 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkCgoBytePool/malloc_unsafeslice2\nBenchmarkCgoBytePool/malloc_unsafeslice2-8           \t 8935269\t       127.8 ns/op\t      16 B/op\t       1 allocs/op\nBenchmarkCgoBytePool/go/malloc\nBenchmarkCgoBytePool/go/malloc-8                     \t 3910248\t       334.4 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkCgoBytePool/go/cgo\nBenchmarkCgoBytePool/go/cgo-8                        \t  943117\t        1166 ns/op\t      96 B/op\t       3 allocs/op\nBenchmarkCgoBytePool/bp\nBenchmarkCgoBytePool/bp-8                            \t 3708741\t       270.5 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkCgoBytePool/cbytes\nBenchmarkCgoBytePool/cbytes-8                        \t  231247\t        5876 ns/op\t   21064 B/op\t       6 allocs/op\nBenchmarkCgoBytePool/cgobytepool_cbytes\nBenchmarkCgoBytePool/cgobytepool_cbytes-8            \t 1795348\t       659.6 ns/op\t     144 B/op\t       3 allocs/op\nPASS\n```\n\n# License\n\nMIT, see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fcgobytepool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctu0%2Fcgobytepool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fcgobytepool/lists"}