yiguolei commented on code in PR #55749:
URL: https://github.com/apache/doris/pull/55749#discussion_r2332197914
##########
be/src/vec/common/custom_allocator.h:
##########
@@ -33,6 +36,73 @@ template <class Key, class T, class Compare = std::less<Key>,
class Allocator = CustomStdAllocator<std::pair<const Key, T>>>
using DorisMap = std::map<Key, T, Compare, Allocator>;
+template <typename T>
+ requires(std::is_trivial_v<T> && std::is_standard_layout_v<T>)
+struct DorisUniqueBufferDeleter : public Allocator<false> {
+ size_t count = 0;
+
+ DorisUniqueBufferDeleter() = default;
+ DorisUniqueBufferDeleter(size_t n) : count(n) {}
+
+ void operator()(T* ptr) const noexcept {
+ if (ptr) {
+ Allocator::free(ptr, count * sizeof(T));
+ }
+ }
+};
+
+template <typename T>
+ requires(std::is_trivial_v<T> && std::is_standard_layout_v<T>)
+class DorisUniqueBufferPtr {
+public:
+ using Deleter = DorisUniqueBufferDeleter<T>;
+
+ DorisUniqueBufferPtr() = default;
+ explicit DorisUniqueBufferPtr(T* ptr) = delete;
+
+ DorisUniqueBufferPtr(std::unique_ptr<T[], Deleter>&& uptr) :
ptr_(std::move(uptr)) {}
+ DorisUniqueBufferPtr(DorisUniqueBufferPtr&& other) :
ptr_(std::move(other.ptr_)) {}
+
+ DorisUniqueBufferPtr& operator=(DorisUniqueBufferPtr&& other) {
+ if (this != &other) {
+ ptr_ = std::move(other.ptr_);
+ }
+ return *this;
+ }
+
+ DorisUniqueBufferPtr(std::nullptr_t) noexcept {}
+
+ void reset(T*) = delete;
Review Comment:
Add comment here to explain why disable this function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]