{"id":13626591,"url":"https://github.com/mitchellh/zig-libgc","last_synced_at":"2025-04-12T23:04:39.158Z","repository":{"id":66228476,"uuid":"439770560","full_name":"mitchellh/zig-libgc","owner":"mitchellh","description":"Zig-friendly library for interfacing with libgc (bdwgc) -- the Boehm-Demers-Weiser conservative garbage collector","archived":false,"fork":false,"pushed_at":"2024-01-19T20:28:24.000Z","size":30,"stargazers_count":175,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-02T23:53:06.794Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitchellh.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":"2021-12-19T03:58:13.000Z","updated_at":"2024-12-31T17:27:39.000Z","dependencies_parsed_at":"2024-01-25T05:09:26.957Z","dependency_job_id":"cecef340-97a5-4831-91aa-2e810547af2c","html_url":"https://github.com/mitchellh/zig-libgc","commit_stats":{"total_commits":18,"total_committers":4,"mean_commits":4.5,"dds":0.2222222222222222,"last_synced_commit":"81541eb496937b75e3463d9a0db1c46882742157"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-libgc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-libgc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-libgc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitchellh%2Fzig-libgc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitchellh","download_url":"https://codeload.github.com/mitchellh/zig-libgc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232721458,"owners_count":18566401,"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-01T21:02:24.461Z","updated_at":"2025-01-06T12:29:48.505Z","avatar_url":"https://github.com/mitchellh.png","language":"Zig","funding_links":[],"categories":["Libraries","Zig"],"sub_categories":[],"readme":"# zig-libgc\n\nThis library implements a Zig allocator that uses the\n[Boehm-Demers-Weiser conservative Garbage Collector (libgc, bdwgc, boehm-gc)](https://github.com/ivmai/bdwgc).\nValues allocated within this allocator do not need to be explicitly\nfreed.\n\n**Should I use a GC with Zig?** _Probably not_, but it depends on your\nuse case. A garbage collector is nice in certain scenarios, can make\nimplementing certain data structures easier (particularly immutable ones),\netc. The nice thing about Zig is you can choose what you want and don't\nwant in the garbage collector.\n\n## Example\n\n```zig\nconst std = @import(\"std\");\nconst gc = @import(\"gc\");\nconst GcAllocator = gc.GcAllocator;\n\npub fn main() !void {\n    var alloc = gc.allocator();\n\n    // We'll write to the terminal\n    const stdout = std.io.getStdOut().writer();\n\n    // Compare the output by enabling/disabling\n    // gc.disable();\n\n    // Allocate a bunch of stuff and never free it, outputting\n    // the heap size along the way. When the GC is enabled,\n    // it'll stabilize at a certain size.\n    var i: u64 = 0;\n    while (i \u003c 10_000_000) : (i += 1) {\n        // This is all really ugly but its not idiomatic Zig code so\n        // just take this at face value. We're doing weird stuff here\n        // to show that we're collecting garbage.\n        var p = @ptrCast(**u8, try alloc.alloc(*u8, @sizeOf(*u8)));\n        var q = try alloc.alloc(u8, @sizeOf(u8));\n        p.* = @ptrCast(*u8, alloc.resize(q, 2 * @sizeOf(u8)).?);\n\n        if (i % 100_000 == 0) {\n            const heap = gc.getHeapSize();\n            try stdout.print(\"heap size: {d}\\n\", .{heap});\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellh%2Fzig-libgc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitchellh%2Fzig-libgc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitchellh%2Fzig-libgc/lists"}