diff options
author | Sven Gothel <[email protected]> | 2020-12-13 21:55:40 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-12-13 21:55:40 +0100 |
commit | cafd8d1f3689135eae36854a9cca4def690045fd (patch) | |
tree | 31c97ca30139f870b97e20bbcf148982b41bbcd7 /src/direct_bt/GATTCharacteristic.cpp | |
parent | 93d956905bcddcc226164296051a9ec20daca722 (diff) |
smart_ptr-1: Handle AttPDUMsg instances via std::unique_ptr instead of std::shared_ptr for more efficancy; Use std::make_unique where possible
smart_ptr change series, commit #1
For high frequent objects, it is desired to reduce resources and overhead as much as possible.
unique_ptr has zero overhead, while shared_ptr own a little storage for the reference counter.
Using unique_ptr forces us to move the instance from the receiving reading thread to the ringbuffer
and moving it out later. Hence the changes in jau::ringbuffer earlier.
Using std::make_unique is not really required, as unique_ptr has no resource overhead,
hence 'unique_ptr( new Something() )' is only one allocation.
However, this smart_ptr change series will review all smart pointer use cases
and in case a shared_ptr is required like DBTDevice of GATTCharacteristic elements of GATTServices etc,
we shall use std::make_shared to fold two allocations into one.
Note: 'shared_ptr( new Something() )' implies two allocations.
Current implementation state allows these optimizations,
as the use cases for these data types are well understood.
Earlier it was not feasible to undertake constraining efforts,
as it was not clear whether other actors like to share a resource, like a uuid_t for example.
Diffstat (limited to 'src/direct_bt/GATTCharacteristic.cpp')
-rw-r--r-- | src/direct_bt/GATTCharacteristic.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/direct_bt/GATTCharacteristic.cpp b/src/direct_bt/GATTCharacteristic.cpp index fc55be5b..f67a1f1c 100644 --- a/src/direct_bt/GATTCharacteristic.cpp +++ b/src/direct_bt/GATTCharacteristic.cpp @@ -104,7 +104,6 @@ std::vector<std::unique_ptr<std::string>> GATTCharacteristic::getPropertiesStrin } std::string GATTCharacteristic::toString() const noexcept { - std::shared_ptr<const uuid_t> service_uuid; uint16_t service_handle_end = 0xffff; GATTServiceRef serviceRef = getServiceUnchecked(); std::string service_uuid_str = ""; @@ -113,7 +112,7 @@ std::string GATTCharacteristic::toString() const noexcept { std::string desc_str = ", descr[ "; if( nullptr != serviceRef ) { - service_uuid = serviceRef->type; + std::unique_ptr<const uuid_t> & service_uuid = serviceRef->type; service_uuid_str = service_uuid->toString(); service_handle_end = serviceRef->endHandle; |