{"id":21427169,"url":"https://github.com/anders-wind/shared_ptr","last_synced_at":"2025-03-16T21:20:54.845Z","repository":{"id":38330497,"uuid":"443846639","full_name":"anders-wind/shared_ptr","owner":"anders-wind","description":"Experiments with shared_ptr implementations","archived":false,"fork":false,"pushed_at":"2023-02-14T21:46:34.000Z","size":354,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T07:45:16.139Z","etag":null,"topics":["cpp"],"latest_commit_sha":null,"homepage":"","language":"CMake","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/anders-wind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-01-02T18:58:22.000Z","updated_at":"2022-01-06T22:45:36.000Z","dependencies_parsed_at":"2024-11-22T21:44:36.340Z","dependency_job_id":"063233ce-6c5b-4217-a6f8-1b3e03b3e85a","html_url":"https://github.com/anders-wind/shared_ptr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anders-wind%2Fshared_ptr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anders-wind%2Fshared_ptr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anders-wind%2Fshared_ptr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anders-wind%2Fshared_ptr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anders-wind","download_url":"https://codeload.github.com/anders-wind/shared_ptr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243933428,"owners_count":20370989,"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"],"created_at":"2024-11-22T21:44:07.047Z","updated_at":"2025-03-16T21:20:54.817Z","avatar_url":"https://github.com/anders-wind.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shared_ptr\n\nExperiments of different shared_ptr implementations. \n\nCurrently there are two different implementations:\n\n- A local not-thread safe `wind::local::shared_ptr`. Structure consist of the pointer to the data and an integer for reference counting.\n- A \"bias\" thread safe `wind::bias::shared_ptr`. Structure consisting of the pointer to the data, an atomic counter for number of threads with copies, and a thread-local counter for number of copies in a thread. This implementation requires support for pthreads.\n\n\n## Experiments:\n\nHypothesis:\n\n- If you do not need thread safety, then `local::shared_ptr` is faster than the alternatives\n- If you share amongst threads and each thread has multiple copies of the ptr then `bias::shared_ptr` is faster.\n- If you have a lot of threads and each thread only has one(or a few) copies then `std::shared_ptr` is the fastest. \n\n\nAll of the experiments have been run on https://www.quick-bench.com and using the `benchmark/source/shared_ptr_benchmark.cpp`. I do not own a pthread supporting system as of writing and therefore I would appreciate any feedback on the benchmarks.\n\nSome benchmark graphs from quickbench - the names of the series corrospond to the specific benchmark:\n\n![](assets/copying.png)\n![](assets/copy_and_release.png)\n![](assets/copy_and_release_many.png)\n![](assets/copy_back_and_forth_between_threads_many_threads_many_copies.png)\n![](assets/copy_back_and_forth_between_threads_many_threads_few_copies.png)\n\n# Building and installing\n\nSee the [BUILDING](BUILDING.md) document.\n\nBut in short:\n```sh\ncmake --preset=dev\ncmake --build --preset=dev\nctest --preset=dev\n```\n\n# Consuming\n\nUse [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake)\n\n```\nCPMAddPackage(\n  NAME benchmark\n  GITHUB_REPOSITORY anders-wind/shared_ptr\n)\n```\nThis creates the cmake target: `wind::shared_ptr` which you can add in your `target_link_libraries`. Then you can add `include \u003cshared_ptr/bias_shared_ptr.hpp\u003e` or `include \u003cshared_ptr/local_shared_ptr.hpp\u003e`\n\n# Contributing\n\nSee the [CONTRIBUTING](CONTRIBUTING.md) document.\n\n# Licensing\n\nSee the [LICENSE](LICENSE) document.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanders-wind%2Fshared_ptr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanders-wind%2Fshared_ptr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanders-wind%2Fshared_ptr/lists"}