MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / align

Function align

Libs/sol/sol.hpp:9831–9846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9829 using unique_tag = detail::inheritance_unique_cast_function;
9830
9831 inline void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space, std::size_t& required_space) {
9832 // this handels arbitrary alignments...
9833 // make this into a power-of-2-only?
9834 // actually can't: this is a C++14-compatible framework,
9835 // power of 2 alignment is C++17
9836 std::uintptr_t initial = reinterpret_cast<std::uintptr_t>(ptr);
9837 std::uintptr_t offby = static_cast<std::uintptr_t>(initial % alignment);
9838 std::uintptr_t padding = (alignment - offby) % alignment;
9839 required_space += size + padding;
9840 if (space < required_space) {
9841 return nullptr;
9842 }
9843 ptr = static_cast<void*>(static_cast<char*>(ptr) + padding);
9844 space -= padding;
9845 return ptr;
9846 }
9847
9848 inline void* align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space) {
9849 std::size_t required_space = 0;

Callers 11

align_oneFunction · 0.85
align_usertype_pointerFunction · 0.85
align_usertype_uniqueFunction · 0.85
align_userFunction · 0.85
attempt_allocFunction · 0.85
attempt_alloc_uniqueFunction · 0.85
user_allocateFunction · 0.85
divmod_assignMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected