{"id":19758049,"url":"https://github.com/benpm/cppmempool","last_synced_at":"2025-10-04T04:45:02.909Z","repository":{"id":89830806,"uuid":"479433233","full_name":"benpm/cppmempool","owner":"benpm","description":"very simple C++ heterogeneous memory pool with thread safety","archived":false,"fork":false,"pushed_at":"2023-10-15T15:40:01.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T22:47:33.932Z","etag":null,"topics":["cpp","memory-allocation","memory-arena","memory-management","memory-pool","smart-pointers"],"latest_commit_sha":null,"homepage":"","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/benpm.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":"2022-04-08T14:58:07.000Z","updated_at":"2023-03-11T15:07:44.000Z","dependencies_parsed_at":"2024-11-12T03:24:32.675Z","dependency_job_id":"83c3db7b-ecf1-44ea-a0da-70bb08543cd2","html_url":"https://github.com/benpm/cppmempool","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/benpm%2Fcppmempool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpm%2Fcppmempool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpm%2Fcppmempool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benpm%2Fcppmempool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benpm","download_url":"https://codeload.github.com/benpm/cppmempool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241089472,"owners_count":19907756,"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":["cpp","memory-allocation","memory-arena","memory-management","memory-pool","smart-pointers"],"created_at":"2024-11-12T03:22:43.973Z","updated_at":"2025-10-04T04:44:57.873Z","avatar_url":"https://github.com/benpm.png","language":"C++","readme":"# :floppy_disk: MemPool\nA *very* simple (only ~150 lines) C++ thread safe heterogenous header-only memory pool class with smart pointer support. Use this if you want to eliminate frequent allocations for **small, short-lived** objects.\n\n## Features\n- Heterogenous types: use any mix of any type in the pool\n- Basic thread safety using `std::mutex`\n- Support for directly creating smart pointers (that's actually all it can do rn... working on it)\n- No dependencies! Not that that's surprising\n- Configured through template arguments\n\n## Limitations\nWith the implementation being this simple, there are definitely some **significant tradeoffs**:\n- Objects allocated cannot be larger than `Chunk::size` (default is 8192 bytes). You *should* get a compiler error if you try this\n- Unused space in allocated chunks is *not reused* until *the entire chunk is empty!* So if some of your objects have long lifetimes, expect your memory usage to just continue growing as you make more allocations in the pool.\n- Blocks are currently not deallocated when empty, but they are re-used\n- Requires C++11\n\n## Usage\n\n```C++\n#include \u003ciostream\u003e\n#include \u003cmempool.hpp\u003e\n\nusing namespace benpm;\n\nstruct Foo {\n    std::string name;\n    int hp;\n    Foo(std::string name, int hp) : name(name), hp(hp) {}\n};\n\nstruct Bar {\n    float val;\n    Bar(float val) : val(val) {}\n};\n\nint main(void) {\n    MemPool pool;\n    std::shared_ptr\u003cFoo\u003e fooA = pool.emplace\u003cFoo\u003e(\"foo A\", 10);\n    std::shared_ptr\u003cBar\u003e barA = pool.emplace\u003cBar\u003e(16.16);\n    std::cout \u003c\u003c fooA-\u003ename \u003c\u003c std::endl;\n    std::cout \u003c\u003c barA-\u003eval \u003c\u003c std::endl;\n    ///TODO: put example for normal allocation and free\n}\n```\nCheck out benchmark.cpp for more\n\n## How it Works\ntodo\n\n## Benchmark\n(This is a work in progress)\n\n| operation                    | time (pool) | time (no pool) |\n| ---------------------------- | ----------- | -------------- |\n| (raw) init insert            |       176ms |          190ms |\n| (raw) random removal         |        51ms |           36ms |\n| (raw) second insert          |        75ms |           78ms |\n| (raw) random access          |       817ms |          898ms |\n| (raw) sequential access      |        18ms |           22ms |\n| (raw) destruction            |       101ms |           72ms |\n| (shared) init insert         |       413ms |          251ms |\n| (shared) random removal      |        55ms |           55ms |\n| (shared) second insert       |       129ms |          108ms |\n| (shared) random access       |       974ms |          930ms |\n| (shared) sequential access   |        19ms |           33ms |\n| (shared) destruction         |       213ms |          120ms |\n\n## Contribution\nI'm still a C++ baby so if you have some ideas for improvement, please feel free to make an issue or a PR!\n\n### Todo\n- [x] Support for non-smart pointer alloc\n- [ ] `std::unique_ptr` support\n- [x] Benchmarks (with both insert after and insert before)\n- [ ] More complex example\n- [x] Block alignment\n- [ ] Explanation of how it works","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenpm%2Fcppmempool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenpm%2Fcppmempool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenpm%2Fcppmempool/lists"}