https://github.com/anders-wind/shared_ptr
Experiments with shared_ptr implementations
https://github.com/anders-wind/shared_ptr
cpp
Last synced: over 1 year ago
JSON representation
Experiments with shared_ptr implementations
- Host: GitHub
- URL: https://github.com/anders-wind/shared_ptr
- Owner: anders-wind
- License: mit
- Created: 2022-01-02T18:58:22.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-14T21:46:34.000Z (over 3 years ago)
- Last Synced: 2025-01-23T07:45:16.139Z (over 1 year ago)
- Topics: cpp
- Language: CMake
- Homepage:
- Size: 346 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# shared_ptr
Experiments of different shared_ptr implementations.
Currently there are two different implementations:
- A local not-thread safe `wind::local::shared_ptr`. Structure consist of the pointer to the data and an integer for reference counting.
- 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.
## Experiments:
Hypothesis:
- If you do not need thread safety, then `local::shared_ptr` is faster than the alternatives
- If you share amongst threads and each thread has multiple copies of the ptr then `bias::shared_ptr` is faster.
- If you have a lot of threads and each thread only has one(or a few) copies then `std::shared_ptr` is the fastest.
All 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.
Some benchmark graphs from quickbench - the names of the series corrospond to the specific benchmark:





# Building and installing
See the [BUILDING](BUILDING.md) document.
But in short:
```sh
cmake --preset=dev
cmake --build --preset=dev
ctest --preset=dev
```
# Consuming
Use [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake)
```
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY anders-wind/shared_ptr
)
```
This creates the cmake target: `wind::shared_ptr` which you can add in your `target_link_libraries`. Then you can add `include ` or `include `
# Contributing
See the [CONTRIBUTING](CONTRIBUTING.md) document.
# Licensing
See the [LICENSE](LICENSE) document.