Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created September 1, 2020 16:44
Show Gist options
  • Save vinniefalco/b1b5a344c8382491590f58d203c58007 to your computer and use it in GitHub Desktop.
Save vinniefalco/b1b5a344c8382491590f58d203c58007 to your computer and use it in GitHub Desktop.
void*
static_resource::
do_allocate(
std::size_t n,
std::size_t align)
{
auto const i = reinterpret_cast<
std::uintptr_t>(buffer_ + used_);
std::size_t const extra = (
align * ((i + align - 1) / align)) - i;
auto const avail = size_ - used_;
if( extra > avail ||
n > avail ||
n > avail - extra)
BOOST_THROW_EXCEPTION(
std::bad_alloc());
auto p = buffer_ + used_ + extra;
used_ += extra + n;
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment