{"id":19338189,"url":"https://github.com/jserv/ogc","last_synced_at":"2026-03-03T12:32:21.400Z","repository":{"id":146557307,"uuid":"130516826","full_name":"jserv/ogc","owner":"jserv","description":"A minimal mark-and-sweep garbage collector","archived":false,"fork":false,"pushed_at":"2019-04-03T04:33:04.000Z","size":7,"stargazers_count":44,"open_issues_count":0,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-22T22:57:06.633Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jserv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-04-21T22:32:04.000Z","updated_at":"2024-04-06T16:14:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"94903237-44f3-4083-b8a2-060bdfc60f00","html_url":"https://github.com/jserv/ogc","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/jserv%2Fogc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Fogc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Fogc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Fogc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jserv","download_url":"https://codeload.github.com/jserv/ogc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250352248,"owners_count":21416461,"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-10T03:16:35.250Z","updated_at":"2026-03-03T12:32:21.336Z","avatar_url":"https://github.com/jserv.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OGC: Ordinary Garbage Collector\n\n## About\n\nOGC implements the typical \"mark and sweep\" algorithm. It works as follows:\n* there is an internal struct representing a block of memory\n* there is a list of blocks representing the allocated memory, and another\n  list representing the local stack of memory\n* once a new object is created,\n    - its memory is allocated and its meta data is added to both lists\n    - there is a threshold for the number of objects to allocate before\n      cleaning up the memory\n    - when the threshold is met:\n        + call \"mark\" with the local stack of memory (\"reachable\" memory)\n        + mark recurses through the list and set a \"mark\" flag for every\n          block reachable from the inital list of reachable memory\n        + we then call \"sweep\" with the global allocated memory list\n        + every block that is not marked is not used, and can be freed and\n          popped from given list\n\n\n## How it works\n\nFor a basic mark and sweep garbage collector, two things are required:\n* a list of all of the allocations made by the program;\n* a list of all the allocations in use by the program at any given time;\n\nWith these two things the algorithm is simple - compare the two lists and\nfree any allocations which are in the first list, but not in the second -\nexactly those allocations which are no longer in use.\n\nTo get a list of all the allocations made by the progam is relatively\nsimple. We make the programmer use a special function we have prepared\n(in this case `gc_alloc`) which allocates memory, and then adds a pointer\nto that memory to an internal list. If at any point this allocation is\nfreed (such as by `gc_free`), it is removed from the list.\n\n\n## Function list\n\n* `gc_alloc()`\n    - Allocates a space in memory of the size which the user requests\n    - Ensures the user entered a number \u003e 0\n    - Attempts to find a freed block of memory to reuse.\n    - On success, returns the address of the newly allocated memory.\n      Otherwise, returns NULL.\n\n* `gc_free()`\n    - Marks the object as free in the list of objects\n    - Ensures the pointer isn't NULL or already free before marking it\n\n* `gc_run()`\n    - Recursively marks all reachable objects in the list of objects\n    - Recursively sweeps (frees) all unmarked (unreachable) objects\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjserv%2Fogc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjserv%2Fogc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjserv%2Fogc/lists"}