{"id":24737542,"url":"https://github.com/engineersbox/c-hybrid-tlsf-fixed-heap","last_synced_at":"2025-06-25T20:06:47.097Z","repository":{"id":42054641,"uuid":"479892696","full_name":"EngineersBox/C-Hybrid-TLSF-fixed-heap","owner":"EngineersBox","description":"A hybrid TLSF fixed heap allocator for managing pre-allocated heap memory.","archived":false,"fork":false,"pushed_at":"2022-04-16T06:02:46.000Z","size":451,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T17:45:01.507Z","etag":null,"topics":["allocator","c","htfh","memory-allocation","memory-management","tlsf"],"latest_commit_sha":null,"homepage":"","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/EngineersBox.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}},"created_at":"2022-04-10T02:24:52.000Z","updated_at":"2022-04-12T15:36:31.000Z","dependencies_parsed_at":"2022-08-12T03:31:12.191Z","dependency_job_id":null,"html_url":"https://github.com/EngineersBox/C-Hybrid-TLSF-fixed-heap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/EngineersBox/C-Hybrid-TLSF-fixed-heap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineersBox%2FC-Hybrid-TLSF-fixed-heap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineersBox%2FC-Hybrid-TLSF-fixed-heap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineersBox%2FC-Hybrid-TLSF-fixed-heap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineersBox%2FC-Hybrid-TLSF-fixed-heap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EngineersBox","download_url":"https://codeload.github.com/EngineersBox/C-Hybrid-TLSF-fixed-heap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineersBox%2FC-Hybrid-TLSF-fixed-heap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261945376,"owners_count":23234237,"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":["allocator","c","htfh","memory-allocation","memory-management","tlsf"],"created_at":"2025-01-27T22:08:38.287Z","updated_at":"2025-06-25T20:06:47.066Z","avatar_url":"https://github.com/EngineersBox.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C-Hybrid-TLSF-fixed-heap\r\n\r\nC UNIX only hybrid TLSF fixed heap allocator for managing pre-allocated heap memory via an anonymous memory map.\r\n\r\n## Credits\r\n\r\nImplementation is based on Matt Conte's TLSF: \u003chttps://github.com/mattconte/tlsf\u003e\r\n\r\n## Methods\r\n\r\n| Signature                                                                   \t             | Description                                                                                                                                                                                                                                                                                                                                              \t                                                           |\r\n|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\r\n| `Allocator* alloc htfh_create(size_t bytes)`                                             \t | Instantiates an new allocator with default values and creates an anonymous memory map of size `bytes` as the heap                                                                                                                                                                                                                                                                                                  \t |\r\n| `int htfh_destroy(Allocator* alloc)`                                        \t               | Handled freeing of allocator with checking on heap state                                                                                                                                                                                                                                                                                                 \t                                                           |\r\n| `void* htfh_malloc(Allocator* alloc, unsigned nbytes)`                       \t            | Allocate memory from the mapped region for a given size                                                                                                                                                                                                                                                                                                  \t                                                           |\r\n| `void* htfh_calloc(Allocator* alloc, unsigned count, unsigned nbytes)`       \t            | Allocate contiguous memory from the mapped region for a given number of elements of given size                                                                                                                                                                                                                                                           \t                                                           |\r\n| `void* htfh_realloc(Allocator* alloc, void* ap, unsigned nbytes)`            \t            | Re-size a given block of memory to a new size, that was previously allocated by `htfh_malloc` or `htfh_calloc`.                                                                                                                                                                                                                                            \t                                                         |\r\n| `void htfh_free(Allocator* alloc, void* ap)`                                 \t            | Free the memory currently held by the provided pointer to a region of the mapped memory                                                                                                                                                                                                                                                                  \t                                                           |\r\n\r\n## Error Handling\r\n\r\nErrors are handled in the same manner as standard usage of `perror(char* prefix)` follows, except with a custom method `alloc_perror(char* prefix)`.\r\nAny call made with the HTFH methods, should follow with a return value check, in the case on an invalid/erroneous value, `alloc_perror(char* prefix)` should be called to display the error, file, line number and function name in stderr.\r\n\r\nAn example of an error being logged as a result of `alloc_perror(\"An error occured: \")` is as follows:\r\n\r\n```\r\nAn error occured: Managed heap has already been allocated\r\n\tat main(/Users/EngineersBox/Desktop/Projects/C:C++/C-fixed-heap-allocator/src/main.c:25)\r\n\tat htfh_init(/Users/EngineersBox/Desktop/Projects/C:C++/C-fixed-heap-allocator/src/allocator/tlsf.c:112)\r\n```\r\n\r\nThese locations correspond the following:\r\n\r\n### Main.c:25\r\n\r\n```c\r\n// ... snip ...\r\nif (htfh_init(alloc, 16 * 10000) != 0) {\r\n    alloc_perror(\"An error occured: \");\r\n    return 1;\r\n}\r\n// ... snip ...\r\n```\r\n\r\n### Tlsf.c:112\r\n\r\n```c\r\n// ... snip ...\r\n} else if (alloc-\u003eheap != NULL) {\r\n    set_alloc_errno(HEAP_ALREADY_MAPPED);\r\n    __htfh_lock_unlock_handled(\u0026alloc-\u003emutex);\r\n    return -1;\r\n}\r\n// ... snip ...\r\n```\r\n\r\n## Usage\r\n\r\nThere are two ways to utilise the allocator, one is through handled static construction and dynamic instantiation.\r\n\r\n### Static\r\n\r\nTODO\r\n\r\n### Dynamic\r\n\r\nTODO\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineersbox%2Fc-hybrid-tlsf-fixed-heap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fengineersbox%2Fc-hybrid-tlsf-fixed-heap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineersbox%2Fc-hybrid-tlsf-fixed-heap/lists"}