Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void * operator new(std::size_t size) {
- constexpr std::size_t align = 4096;
- std::size_t request = sizeof(Plate<rows, columns>) + align;
- const std::size_t needed = request + sizeof(void*);
- void * buffer = ::operator new(needed);
- void * starting_location = buffer + sizeof(void*);
- void * ptr = nonstd::align(align, sizeof(Plate<rows,columns>), starting_location, request);
- ((void **) ptr)[-1] = buffer;
- return ptr;
- }
- namespace nonstd {
- /* At time of this writing I did not have an implementation of C++11's
- * std::align; this is modified code from:
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57350
- */
- inline void *align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space ) {
- std::uintptr_t pn = reinterpret_cast<std::uintptr_t>( ptr );
- std::uintptr_t aligned = (pn + alignment - 1) & - alignment;
- std::size_t padding = aligned - pn;
- if (space < size + padding) {
- return nullptr;
- }
- space -= padding;
- return ptr = reinterpret_cast<void *>(aligned);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement