aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt/UUID.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-12-13 21:55:40 +0100
committerSven Gothel <[email protected]>2020-12-13 21:55:40 +0100
commitcafd8d1f3689135eae36854a9cca4def690045fd (patch)
tree31c97ca30139f870b97e20bbcf148982b41bbcd7 /src/direct_bt/UUID.cpp
parent93d956905bcddcc226164296051a9ec20daca722 (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/UUID.cpp')
-rw-r--r--src/direct_bt/UUID.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/direct_bt/UUID.cpp b/src/direct_bt/UUID.cpp
index 97b2fe81..55e27397 100644
--- a/src/direct_bt/UUID.cpp
+++ b/src/direct_bt/UUID.cpp
@@ -44,13 +44,13 @@ uuid_t::TypeSize uuid_t::toTypeSize(const jau::nsize_t size) {
throw jau::IllegalArgumentException("Given size "+std::to_string(size)+", not matching uuid16_t, uuid32_t or uuid128_t", E_FILE_LINE);
}
-std::shared_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const buffer, jau::nsize_t const byte_offset, bool littleEndian) {
+std::unique_ptr<const uuid_t> uuid_t::create(TypeSize t, uint8_t const * const buffer, jau::nsize_t const byte_offset, bool littleEndian) {
if( TypeSize::UUID16_SZ == t ) {
- return std::shared_ptr<const uuid_t>(new uuid16_t(buffer, byte_offset, littleEndian));
+ return std::unique_ptr<const uuid_t>(new uuid16_t(buffer, byte_offset, littleEndian));
} else if( TypeSize::UUID32_SZ == t ) {
- return std::shared_ptr<const uuid_t>(new uuid32_t(buffer, byte_offset, littleEndian));
+ return std::unique_ptr<const uuid_t>(new uuid32_t(buffer, byte_offset, littleEndian));
} else if( TypeSize::UUID128_SZ == t ) {
- return std::shared_ptr<const uuid_t>(new uuid128_t(buffer, byte_offset, littleEndian));
+ return std::unique_ptr<const uuid_t>(new uuid128_t(buffer, byte_offset, littleEndian));
}
throw jau::IllegalArgumentException("Unknown Type "+std::to_string(static_cast<jau::nsize_t>(t)), E_FILE_LINE);
}