- data_deleter() : type_(Free) {}
- data_deleter(Type type, std::size_t size) : type_(type), size_(size) {}
- void operator()(void* p) const;
-};
+ Buffer() = default;
+ void clear() noexcept;
+ ~Buffer() noexcept { clear(); }
+
+ static Buffer malloc(std::size_t size)
+ {
+ return Buffer(size, Type::Malloc);
+ }
+ static Buffer mmap(std::size_t size)
+ {
+ return Buffer(size, Type::Mmap);
+ }
+
+ // No copy
+ Buffer(Buffer const& buffer) = delete;
+ Buffer& operator=(Buffer const& buffer) = delete;
+
+ // Move
+ Buffer(Buffer&& that) noexcept
+ : data_(that.data_), size_(that.size_), type_(that.type_)
+ {
+ that.data_ = nullptr;
+ that.size_ = 0;
+ that.type_ = Type::Malloc;
+ }
+ Buffer& operator=(Buffer&& that) noexcept
+ {
+ clear();
+ data_ = that.data_;
+ size_ = that.size_;
+ type_ = that.type_;
+ that.data_ = nullptr;
+ that.size_ = 0;
+ that.type_ = Type::Malloc;
+ return *this;
+ }