+ 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;
+ }
+
+ void* get() { return data_; }
+ const void* get() const { return data_; }
+ std::size_t size() const { return size_; }
+};