Coalescing Pool MemoryΒΆ
The umpire::strategy::DynamicPool
provides a
umpire::strategy::DynamicPool::coalesce()
that can be used to release
unused memory and allocate a single large block that will be able to satisfy
allocations up to the previously observed high-watermark. To call this
function, you must get the pointer to the
umpire::strategy::AllocationStrategy
from the
umpire::Allocator
:
auto dynamic_pool =
umpire::util::unwrap_allocator<umpire::strategy::DynamicPool>(pool);
Once you have the pointer to the appropriate strategy, you can call the function:
dynamic_pool->coalesce();
The complete example is included below:
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016-19, Lawrence Livermore National Security, LLC and Umpire
// project contributors. See the COPYRIGHT file for details.
//
// SPDX-License-Identifier: (MIT)
//////////////////////////////////////////////////////////////////////////////
#include "umpire/strategy/DynamicPool.hpp"
#include "umpire/strategy/AllocationTracker.hpp"
#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "umpire/util/Exception.hpp"
#include "umpire/util/wrap_allocator.hpp"
#include <iostream>
int main(int, char**) {
auto& rm = umpire::ResourceManager::getInstance();
auto pool = rm.makeAllocator<umpire::strategy::DynamicPool>(
"pool", rm.getAllocator("HOST"));
auto dynamic_pool =
umpire::util::unwrap_allocator<umpire::strategy::DynamicPool>(pool);
if (dynamic_pool) {
dynamic_pool->coalesce();
} else {
UMPIRE_ERROR(pool.getName() << " is not a DynamicPool, cannot coalesce!");
}
return 0;
}