Created
September 1, 2020 16:44
-
-
Save vinniefalco/b1b5a344c8382491590f58d203c58007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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