\brief bytes class \note This is a buffer wrapper that maps to a bo_buffer or other memory without performing a deep copy. \note A copy (or mapping) does not duplicate the underlying memory; it only maps the pointer.
| 31 | /// \note This is a buffer wrapper that maps to a bo_buffer or other memory without performing a deep copy. |
| 32 | /// \note A copy (or mapping) does not duplicate the underlying memory; it only maps the pointer. |
| 33 | class bytes { |
| 34 | protected: |
| 35 | std::unique_ptr<uint8_t[]> owned_data_; |
| 36 | uint8_t* data_; |
| 37 | size_t size_; |
| 38 | bool is_owner_; |
| 39 | #ifdef __XRT__ |
| 40 | bool is_bo_owner_; |
| 41 | xrt::bo* bo_; |
| 42 | std::unique_ptr<xrt::bo> owned_bo_; |
| 43 | #endif |
| 44 | |
| 45 | public: |
| 46 | /// \brief constructor |
| 47 | /// \note This is a buffer wrapper that maps to a bo_buffer or other memory without performing a deep copy. |
| 48 | /// \note A copy (or mapping) does not duplicate the underlying memory; it only maps the pointer. |
| 49 | bytes() : data_(nullptr), size_(0), is_owner_(false) |
| 50 | #ifdef __XRT__ |
| 51 | , is_bo_owner_(false), bo_(nullptr), owned_bo_(nullptr) |
| 52 | #endif |
| 53 | {} |
| 54 | |
| 55 | /// \brief copy constructor |
| 56 | /// \param other the other bytes |
| 57 | bytes(const bytes& other) : owned_data_(nullptr), data_(other.data_), size_(other.size_), is_owner_(false) |
| 58 | #ifdef __XRT__ |
| 59 | , is_bo_owner_(false), bo_(other.bo_), owned_bo_(nullptr) |
| 60 | #endif |
| 61 | {} |
| 62 | |
| 63 | /// \brief move constructor |
| 64 | /// \param other the other bytes |
| 65 | bytes(bytes&& other) noexcept |
| 66 | : owned_data_(std::move(other.owned_data_)), data_(other.data_), size_(other.size_), is_owner_(other.is_owner_) |
| 67 | #ifdef __XRT__ |
| 68 | , is_bo_owner_(other.is_bo_owner_), bo_(other.bo_), owned_bo_(std::move(other.owned_bo_)) |
| 69 | #endif |
| 70 | { |
| 71 | other.data_ = nullptr; |
| 72 | other.size_ = 0; |
| 73 | other.is_owner_ = false; |
| 74 | #ifdef __XRT__ |
| 75 | other.is_bo_owner_ = false; |
| 76 | other.bo_ = nullptr; |
| 77 | other.owned_bo_ = nullptr; |
| 78 | #endif |
| 79 | } |
| 80 | |
| 81 | /// \brief constructor |
| 82 | /// \param size the size |
| 83 | bytes(size_t size) |
| 84 | : size_(size), is_owner_(true) |
| 85 | #ifdef __XRT__ |
| 86 | , is_bo_owner_(false), bo_(nullptr), owned_bo_(nullptr) |
| 87 | #endif |
| 88 | { |
| 89 | if (size > 0 && size < 8ull * 1024 * 1024 * 1024){ |
| 90 | try { |
no test coverage detected