{"id":16317678,"url":"https://github.com/zfletch/zmalloc-c","last_synced_at":"2025-05-13T16:33:01.006Z","repository":{"id":15915543,"uuid":"18657241","full_name":"zfletch/zmalloc-c","owner":"zfletch","description":"Memory Allocator","archived":false,"fork":false,"pushed_at":"2015-10-18T13:18:38.000Z","size":180,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T20:20:57.661Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zfletch.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}},"created_at":"2014-04-11T00:41:12.000Z","updated_at":"2015-03-24T21:37:02.000Z","dependencies_parsed_at":"2022-09-22T06:50:29.290Z","dependency_job_id":null,"html_url":"https://github.com/zfletch/zmalloc-c","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/zfletch%2Fzmalloc-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfletch%2Fzmalloc-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfletch%2Fzmalloc-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfletch%2Fzmalloc-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zfletch","download_url":"https://codeload.github.com/zfletch/zmalloc-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253981908,"owners_count":21994353,"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-10-10T22:09:00.407Z","updated_at":"2025-05-13T16:33:00.938Z","avatar_url":"https://github.com/zfletch.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Memory Allocator\n\nThis is a memory allocator in C. It uses the [buddy system](https://en.wikipedia.org/wiki/Buddy_memory_allocation)\nto avoid fragmentation. The public interface includes the standard `malloc`, `calloc`, `realloc`, and `free`.\n\n## Example\n```c\n#include \u003cstdio.h\u003e\n#include \"../src/zmalloc.h\"\n\n// gcc -Wall -Wextra hello.c ../src/zmalloc.c\n// prints \"hello world\" to stdout\nint main()\n{\n  char *world;\n  \n  world = zmalloc(6 * sizeof(char));\n  world[0] = 'w'; world[1] = 'o'; world[2] = 'r';\n  world[3] = 'l'; world[4] = 'd'; world[5] = '\\0';\n  \n  printf(\"hello %s\\n\", world);\n  \n  zfree(world);\n  \n  return 0;\n}\n```\n\n## Public Interface\n```c\n// given an unsigned integer, size\n// returns a pointer to a place in memory with at least size bytes\n// will be 8-byte (double-word) aligned\n// will return NULL if memory cannot be allocated or 0 is passed in\nvoid* zmalloc(size_t size);\n\n// deallocates memory allocated by zmalloc\nvoid zfree(void* ptr);\n\n// changes the size of the block that ptr points to\n// possibly moving the memory to somewhere else\nvoid* zrealloc(void* ptr, size_t size);\n\n// allocates num * size bytes and initializes them to 0\nvoid* zcalloc(size_t num, size_t size);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfletch%2Fzmalloc-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzfletch%2Fzmalloc-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfletch%2Fzmalloc-c/lists"}