\brief resize \param new_size the new size
| 249 | /// \brief resize |
| 250 | /// \param new_size the new size |
| 251 | void resize(size_t new_size) { |
| 252 | #ifdef __XRT__ |
| 253 | assert(!is_bo_owner_); |
| 254 | #endif |
| 255 | if (data_ != nullptr && !is_owner_) { |
| 256 | throw std::runtime_error("Cannot resize a non-owner buffer"); |
| 257 | } |
| 258 | if (new_size == 0) { |
| 259 | throw std::runtime_error("Cannot resize to zero size"); |
| 260 | } |
| 261 | try { |
| 262 | owned_data_.reset(new uint8_t[new_size]); |
| 263 | } |
| 264 | catch (const std::bad_alloc& e) { |
| 265 | throw std::runtime_error(std::string("Failed to allocate bytes of size ") + std::to_string(new_size) + ": " + e.what()); |
| 266 | } |
| 267 | data_ = owned_data_.get(); |
| 268 | size_ = new_size; |
| 269 | is_owner_ = true; |
| 270 | } |
| 271 | |
| 272 | /// \brief free, release the memory or the bo |
| 273 | void free() { |