bytecode_ptr: add shrink() member function

This commit is contained in:
Justin Viiret
2017-04-05 16:58:53 +10:00
committed by Matthew Barr
parent 82b889f4a2
commit d4146059db
2 changed files with 14 additions and 0 deletions

View File

@@ -101,6 +101,19 @@ public:
swap(alignment, other.alignment);
}
/**
* \brief Reduces the apparent size of the memory region. Note that this
* does not reallocate and copy, it just changes the value returned by
* size().
*/
void shrink(size_t size) {
if (size > bytes) {
assert(0);
throw std::logic_error("Must shrink to a smaller value");
}
bytes = size;
}
/** \brief Returns size of the memory region in bytes. */
size_t size() const { return bytes; }