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

@ -337,6 +337,7 @@ bytecode_ptr<FDRConfirm> getFDRConfirm(const vector<hwlmLiteral> &lits,
size_t actual_size = ROUNDUP_N((size_t)(ptr - fdrc_base), size_t actual_size = ROUNDUP_N((size_t)(ptr - fdrc_base),
alignof(FDRConfirm)); alignof(FDRConfirm));
assert(actual_size <= size); assert(actual_size <= size);
fdrc.shrink(actual_size);
return fdrc; return fdrc;
} }

View File

@ -101,6 +101,19 @@ public:
swap(alignment, other.alignment); 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. */ /** \brief Returns size of the memory region in bytes. */
size_t size() const { return bytes; } size_t size() const { return bytes; }