wip
This commit is contained in:
parent
c5aae5148e
commit
4d940ab096
@ -14,6 +14,26 @@ namespace osrm::util
|
|||||||
{
|
{
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
|
class Cleanup {
|
||||||
|
public:
|
||||||
|
static void CleanupAtExit(void* p) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
allocated_blocks_.push_back(static_cast<char*>(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
~Cleanup() {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
for (auto block : allocated_blocks_) {
|
||||||
|
std::free(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::vector<void*> allocated_blocks_;
|
||||||
|
static std::mutex mutex_;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T, size_t MinItemsInBlock = 1024>
|
template <typename T, size_t MinItemsInBlock = 1024>
|
||||||
class PoolAllocator;
|
class PoolAllocator;
|
||||||
|
|
||||||
@ -57,12 +77,12 @@ public:
|
|||||||
|
|
||||||
~MemoryManager()
|
~MemoryManager()
|
||||||
{
|
{
|
||||||
for (auto block : blocks_)
|
// std::cerr << "~MemoryManager()" << std::endl;
|
||||||
{
|
// for (auto block : blocks_)
|
||||||
std::free(block);
|
// {
|
||||||
}
|
// std::free(block);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MemoryManager() = default;
|
MemoryManager() = default;
|
||||||
MemoryManager(const MemoryManager &) = delete;
|
MemoryManager(const MemoryManager &) = delete;
|
||||||
@ -84,6 +104,8 @@ private:
|
|||||||
{
|
{
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
Cleanup::CleanupAtExit(block);
|
||||||
|
|
||||||
total_allocated_ += block_size;
|
total_allocated_ += block_size;
|
||||||
blocks_.push_back(block);
|
blocks_.push_back(block);
|
||||||
current_block_ptr_ = block;
|
current_block_ptr_ = block;
|
||||||
|
Loading…
Reference in New Issue
Block a user