Add polymorphic allocator and memory resource
Reference issue
Adds the polymorphic allocator requested in issue #2354 and detailed in !1608 (closed)
What does this implement/fix?
For ease of review I split up the proposal from !1608 (closed) into two PRs. This is the first PR which adds the memory resource and polymorphic allocator classes. The second PR will put this into Eigen types
In total this adds:
-
memory_resourceA virtual base class that will be used as a base for all of Eigen's memory resources. -
new_delete_resourceThe memory resource to be used by default for Eigen types that uses Eigen's handmade malloc and free functions to request memory -
monotonic_buffer_resourceMemory resource for allocating blocks of memory monotonically to be reused and then free'd all at once -
polymorphic_allocatorEigen's equivalent tostd::pmr::memory_resource. Memory resources are given to the polymorphic allocator and will be used in Eigen types for allocating and deallocating memory.
When the user is compiling with a standard greater than or equal to 17 Eigen::memory_resource is an alias for std::pmr::memory_resource. For the polymorphic allocator, it inherits from std::pmr::polymorphic_allocator<byte_t> when the user compiles with >= 17. This is because the design doc's allocate and deallocate functions vary from the standards polymorphic allocator by having a template parameter on them so it could not be a direct alias.