[K/N] Track current heap size ^KT-55364

This commit is contained in:
Alexander Shabalin
2023-04-11 13:41:48 +02:00
committed by Space Cloud
parent 18b6351d5d
commit cb7698a8c2
24 changed files with 175 additions and 52 deletions
@@ -12,13 +12,15 @@ namespace kotlin {
void initObjectPool() noexcept;
void* allocateInObjectPool(size_t size) noexcept;
void freeInObjectPool(void* ptr) noexcept;
void freeInObjectPool(void* ptr, size_t size) noexcept;
// Instruct the allocator to free unused resources.
void compactObjectPoolInCurrentThread() noexcept;
// Platform dependent. Schedule `compactObjectPoolInCurrentThread` on the main thread.
// May do nothing if the main thread is not an event loop.
void compactObjectPoolInMainThread() noexcept;
size_t allocatedBytes() noexcept;
template <typename T>
struct ObjectPoolAllocator {
using value_type = T;
@@ -36,7 +38,7 @@ struct ObjectPoolAllocator {
T* allocate(std::size_t n) noexcept { return static_cast<T*>(allocateInObjectPool(n * sizeof(T))); }
void deallocate(T* p, std::size_t n) noexcept { freeInObjectPool(p); }
void deallocate(T* p, std::size_t n) noexcept { freeInObjectPool(p, n * sizeof(T)); }
};
template <typename T, typename U>