diff --git a/inc/mkn/kul/alloc.hpp b/inc/mkn/kul/alloc.hpp index 05b028a..a397b42 100644 --- a/inc/mkn/kul/alloc.hpp +++ b/inc/mkn/kul/alloc.hpp @@ -36,7 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace mkn::kul { -template +template class AlignedAllocator { using This = AlignedAllocator; public: @@ -54,8 +54,11 @@ class AlignedAllocator { T* allocate(std::size_t const n) const { if (n == 0) return nullptr; - void* p = std::aligned_alloc(alignment, n * sizeof(T)); + auto size = n * sizeof(T); + std::uint32_t diff = size % alignment; + if(diff > 0) diff = alignment - diff; + void* p = std::aligned_alloc(alignment, size + diff); if (!p) throw std::bad_alloc(); return static_cast(p); @@ -81,3 +84,4 @@ class AlignedAllocator { } // namespace mkn::kul #endif /*_MKN_KUL_ALLOC_HPP_*/ + diff --git a/inc/mkn/kul/span.hpp b/inc/mkn/kul/span.hpp index b034ea1..8857ed3 100644 --- a/inc/mkn/kul/span.hpp +++ b/inc/mkn/kul/span.hpp @@ -69,6 +69,19 @@ class Span { auto end() const { return ptr + s; } SIZE const& size() const { return s; } + template , bool> = 0> + void reset(C& c) { + ptr = c.data(); + s = c.size(); + } + + template , bool> = 0> + auto& operator=(C& c) { + reset(c); + return *this; + } + + private: T* ptr = nullptr; SIZE s = 0;