Inherits AllocationPolicy.
template<class T, typename AllocationPolicy>
class gmx::Allocator< T, AllocationPolicy >
Policy-based memory allocator.
- Template Parameters
-
T | Type of objects to allocate |
AllocationPolicy | Policy of (matching) allocation and deallocation functions. |
This class can be used for the optional allocator template parameter in standard library containers. It must be configured with both the type of object to allocate, and an AllocationPolicy which effectively wraps a matching pair of malloc and free functions. This permits implementing a family of related allocators e.g. with SIMD alignment, GPU host-side page locking, or perhaps both, in a way that preserves a common programming interface and duplicates minimal code.
AllocationPolicy is used as a base class, so that if AllocationPolicy is stateless, then the empty base optimization will ensure that Allocation is also stateless, and objects made with the Allocator will incur no size penalty. (Embedding an AllocationPolicy object incurs a size penalty always, even if the object is empty.) Normally a stateless allocator will be used.
However, an AllocationPolicy with state might be desirable for simplifying writing code that needs to allocate suitably for a transfer to a GPU. That code needs to specify an Allocator that can do the right job, which can be stateless. However, if we have code that will not know until run time whether a GPU transfer will occur, then the allocator needs to be aware of the state. That will increase the size of a container that uses the stateful allocator.
- Exceptions
-
std::bad_alloc | Instead of a GROMACS exception object, we throw the standard one on allocation failures to make it as compatible as possible with the errors expected by code using the standard library containers. |
template<class T , typename AllocationPolicy >
template<class T2 , class A = AllocationPolicy, typename = std::enable_if_t<std::is_empty<A>::value>>
Return true if two allocators are identical.
This is a member function of the left-hand-side allocator. Always true for stateless policies. Has to be defined in the policy for stateful policies. FUTURE: Can be removed with C++17 (is_always_equal)
- Todo:
- Use std::is_empty_v when CUDA 11 is a requirement.