Skip to content

Instantly share code, notes, and snippets.

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