Coalescing Pool MemoryΒΆ
The umpire::strategy::QuickPool
provides a
umpire::strategy::QuickPool::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 quick_pool = umpire::util::unwrap_allocator<umpire::strategy::QuickPool>(pool);
Once you have the pointer to the appropriate strategy, you can call the function:
quick_pool->coalesce();
The complete example is included below:
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016-22, Lawrence Livermore National Security, LLC and Umpire
// project contributors. See the COPYRIGHT file for details.
//
// SPDX-License-Identifier: (MIT)
//////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "umpire/strategy/QuickPool.hpp"
#include "umpire/util/Exception.hpp"
#include "umpire/util/wrap_allocator.hpp"
int main(int, char**)
{
auto& rm = umpire::ResourceManager::getInstance();
auto pool = rm.makeAllocator<umpire::strategy::QuickPool>("pool", rm.getAllocator("HOST"));
// _sphinx_tag_tut_unwrap_strategy_start
auto quick_pool = umpire::util::unwrap_allocator<umpire::strategy::QuickPool>(pool);
// _sphinx_tag_tut_unwrap_strategy_end
if (quick_pool) {
// _sphinx_tag_tut_call_coalesce_start
quick_pool->coalesce();
// _sphinx_tag_tut_call_coalesce_end
} else {
UMPIRE_ERROR(pool.getName() << " is not a QuickPool, cannot coalesce!");
}
return 0;
}