#ifndef memory_hh_INCLUDED #define memory_hh_INCLUDED #include #include "assert.hh" namespace Kakoune { enum class MemoryDomain { Undefined, String, InternedString, BufferContent, BufferMeta, WordDB }; template struct UsedMemory { static size_t byte_count; }; template size_t UsedMemory::byte_count = 0; template struct Allocator { using value_type = T; Allocator() = default; template Allocator(const Allocator&) {} template struct rebind { using other = Allocator; }; T* allocate(size_t n) { size_t size = sizeof(T) * n; UsedMemory::byte_count += size; return reinterpret_cast(malloc(size)); } void deallocate(T* ptr, size_t n) { size_t size = sizeof(T) * n; kak_assert(UsedMemory::byte_count >= size); UsedMemory::byte_count -= size; free(ptr); } }; template bool operator==(const Allocator& lhs, const Allocator& rhs) { return d1 == d2; } template bool operator!=(const Allocator& lhs, const Allocator& rhs) { return d1 != d2; } } #endif // memory_hh_INCLUDED