#pragma once #include <3ds.h> #include #include // Write own LinearAllocator for learning namespace Palladium { template class LinearAllocator : public std::allocator { public: typedef size_t size_type; typedef T* pointer; typedef const T* const_pointer; template struct rebind { typedef LinearAllocator other; }; pointer allocate(size_type n, const void* hint = nullptr) { if (n > this->max_size()) { Palladium::Error( "Linear Allocator: \nBad Alloc -> size is larger than free space!"); return nullptr; } return (pointer)linearAlloc(n * sizeof(T)); } void deallocate(pointer p, size_type) { linearFree((void*)p); } size_type max_size() { return linearSpaceFree(); } LinearAllocator() throw() {} LinearAllocator(const LinearAllocator& a) throw() : std::allocator(a) {} ~LinearAllocator() throw() {} }; } // namespace Palladium