-
Notifications
You must be signed in to change notification settings - Fork 61
Open
Description
Coming back to this (was partly discussed off-line elsewhere). I am looking at supporting the use of umpire for large fields, as well as standard new[] for smaller fields. Now run into the slight problem of needing to handle the deletions differently. This is one idea:
namespace Foam::memoryPool
{
//- Deallocate iff actually managed by Umpire
inline bool deallocate_if(void *ptr)
{
if (ptr)
{
if
(
auto& rm = umpire::ResourceManager::getInstance();
rm.hasAllocator(ptr)
)
{
rm.deallocate(ptr);
return true;
}
}
return false;
}
} // End namespace Foam::memoryPool
It's not really pretty, but could perhaps be made more efficient if the hasAllocator returned a pointer to the Allocator instead (which could also be tested as bool). Then the code would look like this:
namespace Foam::memoryPool
{
//- Deallocate iff actually managed by Umpire
inline bool deallocate_if(void *ptr)
{
// Assuming we could have an internal short-circuit for nullptr
if (auto* handler = umpire::ResourceManager::getInstance().hasAllocator(ptr))
{
handler->deallocate(ptr);
return true;
}
return false;
}
} // End namespace Foam::memoryPool
This would avoid calling findAllocatorForPointer twice (not sure how expensive that is).
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels