{"id":13710584,"url":"https://github.com/hmusgrave/zcirc","last_synced_at":"2025-05-06T19:32:13.770Z","repository":{"id":141012480,"uuid":"451657571","full_name":"hmusgrave/zcirc","owner":"hmusgrave","description":"A dynamic circular buffer allocator for zig","archived":false,"fork":false,"pushed_at":"2022-02-13T15:52:18.000Z","size":25,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-13T21:44:31.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hmusgrave.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}},"created_at":"2022-01-24T22:40:25.000Z","updated_at":"2024-06-02T08:15:41.000Z","dependencies_parsed_at":"2024-01-25T05:09:24.830Z","dependency_job_id":"a9f08dcb-a238-497e-88b3-b61852bc1b1d","html_url":"https://github.com/hmusgrave/zcirc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmusgrave%2Fzcirc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmusgrave%2Fzcirc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmusgrave%2Fzcirc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmusgrave%2Fzcirc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hmusgrave","download_url":"https://codeload.github.com/hmusgrave/zcirc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252753630,"owners_count":21798984,"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-08-02T23:00:58.593Z","updated_at":"2025-05-06T19:32:08.741Z","avatar_url":"https://github.com/hmusgrave.png","language":"Zig","funding_links":[],"categories":["Libraries","Language Essentials"],"sub_categories":["Memory Allocator and Management"],"readme":"# zcirc\n\nA dynamic circular buffer allocator for zig\n\n## Purpose\n\nOne use case for circular buffers is handling allocations that depend on\nprevious allocations, after which the previous data is no longer necessary.\nThis library handles that use case when you don't know ahead of time how much\nmemory you might need and can't afford the worst-case latency of a resize operation.\n\n## Installation\n\nChoose your favorite method for vendoring this code into your repository. I\nthink [git-subrepo](https://github.com/ingydotnet/git-subrepo) strikes a nicer\nbalance than git-submodules or most other alternatives.\n\nWhen Zig gets is own builtin package manager we'll be available there as well.\n\n```bash\ngit subrepo clone git+https://github.com/hmusgrave/zcirc.git [optional-subdir]\n```\n\n## Examples\n```zig\nconst std = @import(\"std\");\nconst CircularAllocator= @import(\"zcirc.zig\").CircularAllocator;\n\ntest \"something\" {\n    // Much like working with an ArenaAllocator\n    var circle = CircularAllocator.init(std.testing.allocator);\n    defer circle.deinit();\n    var allocator = circle.allocator();\n\n    // Allocations work like any other allocator\n    var a = try allocator.create(u32);\n    a.* = 12;\n    var b = try allocator.alloc(u8, a.*);\n\n    // The total \"busy\" bytes in our internal buffers include the\n    // space for a and b, plus some slop for alignment and bookkeeping\n    const overhead = @alignOf(CircularAllocator.Meta) + @sizeOf(CircularAllocator.Meta) - 2;\n    try std.testing.expectEqual(\n        (b.len + @sizeOf(u32)) + (@alignOf(u8) + @alignOf(u32)) + 2*overhead,\n        circle.count()\n    );\n\n    // Deletes all data up through (including) the pointer `a`\n    circle.free_left(a);\n\n    // The total \"busy\" bytes only track space used for `b` now\n    try std.testing.expectEqual(b.len + @alignOf(u8) + overhead, circle.count());\n\n    // Deletes all data from (including) the slice `b`\n    circle.free_right(b);\n\n    // Our internal buffers are completely empty. New allocations will\n    // attempt to reuse that space.\n    try std.testing.expectEqual(@as(usize, 0), circle.count());\n}\n```\n\n## Status\nContributions welcome. I'll check back on this repo at least once per month.\nCurrently targets Zig 0.10.*-dev.\n\nThe test suite isn't very complete yet, but any bugs should be superficial at\nthis point.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmusgrave%2Fzcirc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhmusgrave%2Fzcirc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmusgrave%2Fzcirc/lists"}