allocPool: Small update for clarity
This commit is contained in:
parent
7479895164
commit
302c2a5f17
@ -10,7 +10,7 @@ objects before giving them to another caller.
|
|||||||
|
|
||||||
We avoid false sharing by keeping a high amount of work per thread. This should
|
We avoid false sharing by keeping a high amount of work per thread. This should
|
||||||
lead to cache lines not being shared between threads. While this pool uses a hashmap
|
lead to cache lines not being shared between threads. While this pool uses a hashmap
|
||||||
and a pivot to make `returnPtr(ptr)` extremely fast, the construction's bottleneck is
|
and a pivot to make `returnPtr(ptr)` extremely fast, the construction's main bottleneck is
|
||||||
in the locking and unlocking of the hashmap's mutex. We need to do this since we cannot
|
in the locking and unlocking of the hashmap's mutex. We need to do this since we cannot
|
||||||
write in a `std::unordered_map` at different hashes concurrently.
|
write in a `std::unordered_map` at different hashes concurrently.
|
||||||
|
|
||||||
@ -40,7 +40,8 @@ Time (milliseconds) required for real allocations when constructing pool: 9
|
|||||||
```
|
```
|
||||||
|
|
||||||
This trivial example shows some performance improvements that would be much more
|
This trivial example shows some performance improvements that would be much more
|
||||||
important should the allocation and construction of the objects be more complex.
|
important should the allocation and construction/destruction of the objects be more
|
||||||
|
complex.
|
||||||
|
|
||||||
## Safety
|
## Safety
|
||||||
AddressSanitizer, LeakSanitizer and ThreadSanitizer have been used to ensure the safety
|
AddressSanitizer, LeakSanitizer and ThreadSanitizer have been used to ensure the safety
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
void returnPtr(T *ptr) {
|
void returnPtr(T *ptr) {
|
||||||
size_t pos = positionMap[ptr];
|
size_t pos = positionMap[ptr];
|
||||||
(vec[pos])->reset();
|
ptr->reset();
|
||||||
std::swap(vec[pos], vec[pivot]);
|
std::swap(vec[pos], vec[pivot]);
|
||||||
positionMap[vec[pos]] = pos;
|
positionMap[vec[pos]] = pos;
|
||||||
positionMap[vec[pivot]] = pivot;
|
positionMap[vec[pivot]] = pivot;
|
||||||
|
Loading…
Reference in New Issue
Block a user