#pragma once #include #include #include #include class GC { template using vector = vector_type; template using tuple = std::tuple; size_t current_size, max_size, interval, forced_clean; bool running, alive; // ptr, dealloc, ref, sz vector> q; std::thread handle; void gc() { } void reg(void* v, uint32_t ref, uint32_t sz, void(*f)(void*) = [](void* v) {free (v); }) { current_size += sz; if (current_size > max_size) gc(); q.push_back({ v, f }); } void daemon() { using namespace std::chrono; while (alive) { if (running) { gc(); std::this_thread::sleep_for(microseconds(interval)); } else { std::this_thread::sleep_for(10ms); } } } void start_deamon() { handle = std::thread(&daemon); alive = true; } void terminate_daemon() { running = false; alive = false; using namespace std::chrono; if (handle.joinable()) { std::this_thread::sleep_for(microseconds(1000 + std::max(static_cast(10000), interval))); handle.join(); } } };