Support C++17 polymorphic memory resources
Describe the feature you would like to be implemented.
Dynamically allocated storage types (like MatrixX[fd]
and VectorX[fd]
) should be able to allocate their memory using a polymorphic allocator. This would allow their use with different allocation strategies.
Would such a feature be useful for other users? Why?
Polymorphic memory resources allow us to easily implement allocators such as stack, pool, and arena allocators. This can greatly improve performance. For example, if the user knows that a small, dynamically allocated matrix will never exceed some (compile-time known) size, one can use std::pmr::monotonic_buffer_resource
to keep the matrix on the stack and never need a call to malloc()/free()
.
Any hints on how to implement the requested feature?
See:
- C++17: Polymorphic Allocators, Debug Resources and Custom Types
- CppCon 2017: Pablo Halpern "Allocators: The Good Parts" (especially starting at 39:13)
- CppCon 2018: Arthur O'Dwyer "An Allocator is a Handle to a Heap"
- CppCon 2017: Bob Steagall "How to Write a Custom Allocator"
Additional resources
See also: #166 #789 #1568 #1963 (closed)
Edited by Patrick Fasano