{"id":50308736,"url":"https://github.com/sidoshiro/trasher","last_synced_at":"2026-05-28T19:00:51.889Z","repository":{"id":87309382,"uuid":"160837709","full_name":"SidoShiro/trasher","owner":"SidoShiro","description":"♻️ C memory pool library for my projects and studies 🚮","archived":false,"fork":false,"pushed_at":"2025-06-25T00:25:52.000Z","size":261,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T00:27:26.222Z","etag":null,"topics":["allocation","c","compact","linux","memory-pool","pools","shell","trasher","unix"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SidoShiro.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-12-07T14:59:09.000Z","updated_at":"2025-06-25T00:25:55.000Z","dependencies_parsed_at":"2025-06-25T00:33:56.162Z","dependency_job_id":null,"html_url":"https://github.com/SidoShiro/trasher","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/SidoShiro/trasher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidoShiro%2Ftrasher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidoShiro%2Ftrasher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidoShiro%2Ftrasher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidoShiro%2Ftrasher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SidoShiro","download_url":"https://codeload.github.com/SidoShiro/trasher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidoShiro%2Ftrasher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33622070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["allocation","c","compact","linux","memory-pool","pools","shell","trasher","unix"],"created_at":"2026-05-28T19:00:26.746Z","updated_at":"2026-05-28T19:00:51.883Z","avatar_url":"https://github.com/SidoShiro.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trasher\n\n[![Makefile CI](https://github.com/SidoShiro/trasher/actions/workflows/makefile.yml/badge.svg)](https://github.com/SidoShiro/trasher/actions/workflows/makefile.yml)\n\nTrasher is a C memory pool tool.\n\n![Trasher Logo](doc/trasher_logo.png)\n\n# Usefulness \n\nAllocate, use, free easily.\n\n\u003e Allocate minimal required\n\n\u003e Avoid memory leaks ;)\n\n\u003e Simple cleaning\n\nThe trasher is very compact and small, it saved me time and ensure leak free programs in C.\n\nAllocate to specific pools, free them as easily.\n\n# How to use trasher\n\n* Copy trasher directory into your directory\n* Make the library from with the provided Makefile\n* Ensure the access to **trasher.h** for your code\n* Link the lib to your project\n\n```sh:\n# If the library is in the standard lib folder of your system:\n\ngcc  test.c -ltrasher\n\n# OR (specify path):\n\ngcc  test.c -L/path/to/lib/lib -ltrasher\n\n# OR (local path):\n\ngcc test.c -L. -ltrasher\n```\n\n### Basic in code (usage)\n\n1. Allocate simple pool\n   `void* = mem(size_t bytes)`\n2. Allocate id pool \n   `void* = mem_id(size_t bytes)`\n3. Allocate name pool\n   `void* = mem_name(size_t bytes, char *pool_name)`\n4. Free a pool, default pool, any id pool or any name pool\n   `free_pool()`, `free_id(size_t id)`, `free_name(char *pool_name)`\n5. Final Free at end of the program\n   `free_pool_all()`\n\n### Advanced\n\n* Rename pool `pool_rename(char *original_name, char *new_name)`\n\n## Robustness \u0026 Safety\n\nThis version includes several safety enhancements:\n* **NULL-safe API:** All functions check for NULL inputs and uninitialized pool managers.\n* **OOM Protection:** Every `malloc` and `realloc` is verified; functions return `NULL` or error codes if memory is exhausted.\n* **String Safety:** Pool names are managed using `strdup` and `free` to prevent buffer overflows and ensure memory isolation.\n* **Const Correctness:** Public APIs use `const` where appropriate to prevent accidental string modification.\n\n## Tests\n\n```sh\n# all tests (requires CUnit and Valgrind)\nmake test\n\n# run robustness suite (no external deps)\nmake test_robustness\n\n# Should run smoothly\nmake test_ok\n\n# Should crash : core dumped (intended behavior for showing unsafe usage)\nmake test_ko\n```\n\n## Logic - Concept\n\nTrasher is a memory pool tool for C programs. It allows you to:\n\n* Allocate memory in a simple and efficient way, using the minimal required resources.\n* Avoid memory leaks by releasing used memory effectively.\n* Easily clean up allocated memory using Trasher's release functions.\n\nTrasher is very compact and lightweight, it saves time and ensures leak-free C programs.\n\nIt is possible to allocate memory in specific pools and release them easily.\n\nTrasher works by automatically creating pools to store allocated memory blocks. It allows for the creation of multiple pools, as well as blocks in a specific pool using an ID or a name (string). It is also possible to release all pools, a specific pool (by ID or name), or all allocated memory using the final release function. If no name is specified when creating a pool, it will be assigned to NULL.\n\n\u003e This current version of Trasher is a compilation of the memory pool tools I developed from scratch during my studies. It includes many different approaches and techniques that I wanted to organize and bring together in one project.\n\n## Trasher - Doc\n\n* User Functions\n\n| Function | Desc. | Args. | Return |\n|----------|-------|-------|--------|\n| `mem`      | Automatic allocation to the first pool | size (size_t) : allocation size in bytes | (void \\*) : allocated block |\n| `mem_name` | Recommended function to use to allocate blocks, create or re-use the pool asked with pool_name | size (size_t) : allocation size in bytes, pool_name (const char \\*pool_name) : pool name | (void \\*) : allocated block |\n| `mem_id`   | Allocate to a specific pool channel | size (size_t) allocation size in bytes, pool_id (size_t) : the id of the pool | (void \\*) : allocated block |\n| `free_pool` | Free the first pool | - | - |\n| `free_id` | Free the pool id, if has name removes it | pool (size_t) : the pool id | - |\n| `free_name` | Free the pool with pool_name as name | pool_name (const char \\*) : the pool name | - |\n| `free_pool_all` | Remove all pools, reset pool_manager | - | - |\n| `pool_status` | Get printed view of the pools, used mainly for debug | - | (many prints) |\n| `pool_give_number_blocks` | Give number of allocated blocks in a pool | id (size_t) | (ssize_t) : number of blocks, -1 if manager NULL, -2 if id out of bounds |\n| `pool_give_name_from_id` | Retrieve name of a pool from id of pool, NULL if error/not found | id (size_t) | name (char \\*) |\n| `pool_give_id_from_name` | Retrieve id of a pool using the name of the pool, return -1 if not found or error | name (const char \\*) | id (ssize_t) |\n| `pool_rename` | Rename a pool name to a new name | const char \\* source_name, const char \\* new_name | int : 1 success, 0 not found, -1 error/OOM |\n\n\n* Dev Level Lib Functions\n\n| Function | Desc. | Args. | Return |\n|----------|-------|-------|--------|\n| `get_pool_manger` | Get the struct which manage the pools and the pools names | char reset : 1 to clear static manager | (struct pool_manager \\*) | \n| `pool_status_debug` | Get printed view of the pools, used mainly for debug, on stderr | - | (many prints) |\n\n\n* Lib data structs\n\n* pool_manager struct\n\n| Field | Type | Desc. |\n|-------|------|-------|\n| `pools_nb` | size_t | Number of current pools |\n| `pools` | struct mem_block \\*\\* | Array of pools first blocks |\n| `names` | char \\*\\* | Array of each name for specific pool |\n\n* mem_block struct\n\n| Field | Type | Desc. |\n|-------|------|-------|\n| `data`  | void \\* | Allocation address given by malloc |\n| `next`  | struct mem_block \\* | Next memory block (linked list) |\n| `data_size` | size_t | Save the size of the allocated block | \n\n## Notes\n\nBehaviour of mixing id pools with named pools : the \"merge effect\"\n\nIf you have a \"PoolA\" named pool. Add block of 128.\nThen add a block of 512 to pool id 1:\nThe pool status will be:\n```\n[0] : [NULL] NULL\n[1] : [\"PoolA\"] 128 -\u003e 512\n```\n\n\u003e Pool 0 has no name, it's reserved for the mem() and free_pool() functions | and mem_id(XXX, 0)\n\n### Performances\n\n* **v1.1** (use of tail blocks)\n  ```\n  Average time for     malloc lib : 0.000564\n  Average time for    trasher lib : 0.000259\n  ```\n\n* **v1.0**\n  ```\n  Average time for     malloc lib : 0.000564\n  Average time for    trasher lib : 0.010310\n  ```\n\n### TODO\n\n* Realloc (wrapper ?)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidoshiro%2Ftrasher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidoshiro%2Ftrasher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidoshiro%2Ftrasher/lists"}