{"id":13730220,"url":"https://github.com/bitshifter/objectpool","last_synced_at":"2025-04-14T02:31:26.717Z","repository":{"id":56035325,"uuid":"54760818","full_name":"bitshifter/objectpool","owner":"bitshifter","description":"Object pool implementation in C++11","archived":false,"fork":false,"pushed_at":"2020-11-29T21:41:25.000Z","size":350,"stargazers_count":97,"open_issues_count":2,"forks_count":22,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T16:41:02.028Z","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":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitshifter.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":"2016-03-26T03:30:47.000Z","updated_at":"2025-02-28T09:37:54.000Z","dependencies_parsed_at":"2022-08-15T11:50:51.107Z","dependency_job_id":null,"html_url":"https://github.com/bitshifter/objectpool","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/bitshifter%2Fobjectpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitshifter%2Fobjectpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitshifter%2Fobjectpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitshifter%2Fobjectpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitshifter","download_url":"https://codeload.github.com/bitshifter/objectpool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248810883,"owners_count":21165195,"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-08-03T02:01:11.732Z","updated_at":"2025-04-14T02:31:26.085Z","avatar_url":"https://github.com/bitshifter.png","language":"C++","readme":"## Object pool allocator\n\nThis is a C++11 implementation of an object pool allocator.\n\nFor more information on object pool allocators and their purpose see \nhttp://gameprogrammingpatterns.com/object-pool.html.\n\nBoth a fixed size pool (`FixedObjectPool`) and a dynamically growing pool\n(`DynamicObjectPool`) implementation are included.\n\nThe main features of this implementation are:\n* `new_object` method uses C++11 std::forward to pass construction arguments\n  to the constructor of the new object being created in the pool\n* `for_each` method will iterate over all live objects in the pool calling\n  the given function on them\n* `delete_all` method will free all pool objects at once, skipping the\n  destructor call for trivial types\n* maintains a freelist of next available pool entry for fast allocation\n\nThese object pool classes are not designed with exceptions in mind as most\ngame code avoids using exceptions.\n\n## Example usage\n\n```cpp\n// some type to be pooled\nstruct Enemy {\n/* some data */\nEnemy(const char* name);\nvoid update(double delta_time);\n};\n\n// created fixed size pool with space for 64 enemies\nFixedObjectPool\u003cEnemy\u003e enemy_pool(64);\n\n// allocate an enemy - construction parameters are forwarded\nEnemy* baddie = enemy_pool.new_object(\"The Mekon\");\n\n// update all live enemies by executing the lambda on all allocated objects\nenemy_pool.for_each([delta_time](Enemy* enemy)\n    {\n        enemy-\u003eupdate(delta_time);\n    });\n\n// delete a single enemy\nenemy_pool.delete_object(baddie);\n\n// delete all enemies at once (beware of dangling pointers)\nenemy_pool.delete_all();\n```\n\n## Implementation details\n\nBoth `FixedObjectPool` and `DynamicObjectPool` are implemented using the\n`ObjectPoolBlock` class.\n\n`ObjectPoolBlock` is a single allocation containing the `ObjectPoolBlock`\ninstance, indices of used pool entries and the pool memory itself.\n\nOccupancy is tracked using indexes into available entries in the block for\nconstant time allocation. The `ObjectPoolBlock` keeps the next free index head.\nThis index can be used to find the next available block entry when allocating\na new entry.\n\nA separate list of indices is used to track occupancy versus reusing object\npool memory for this purpose to avoid polluting CPU caches with objects which\nare deleted and thus no longer in use.\n\n## Unit testing\n\nUnit tests are written using the [Catch](https://github.com/philsquared/Catch)\nunit testing framework. Unit tests are run through the `runtest` executable.\n\n## Micro-benchmarking\n\nThis repository also includes `bench.hpp` which is a single header file\nmicro-benchmarking framework inspired by Catch and Rust's\n[benchmarking tests](https://doc.rust-lang.org/book/benchmark-tests.html).\n\nIt's my intention to make this standalone at some point but at the\nmoment it's very much a work in progress.\n\nCurrently each micro-benchmark compares the performance of the following:\n* Fixed pool\n* Dynamic pool with 64, 128 and 256 entry blocks\n* The default allocator\n\nBenchmarks output nanoseconds per iteration (lower is better) and megabytes per\nsecond throughput (higher is better).\n\n## Prerequisites\n\nThe test and benchmarking applications require [CMake](http://www.cmake.org) to\ngenerate build files.\n\n## Compiling and running\n\nTo generate a build, compile and run follow these steps:\n\n~~~\nmkdir build\ncd build\ncmake -DCMAKE_BUILD_TYPE=Release ..\nmake\n./runtests\n./runbench\n~~~\n\n## License\n\nThis software is licensed under the zlib license, see the LICENSE file for\ndetails.\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitshifter%2Fobjectpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitshifter%2Fobjectpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitshifter%2Fobjectpool/lists"}