template<class T = void *>
class Malloc_allocator< T >
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
This allows for P_S instrumentation of memory allocation done by internally by STL container classes.
Example usage: vector<int, Malloc_allocator<int>> v((Malloc_allocator<int>(PSI_NOT_INSTRUMENTED)));
If the type is complicated, you can just write Malloc_allocator<>(psi_key) as a shorthand for Malloc_allocator<My_complicated_type>(psi_key), as all Malloc_allocator instances are implicitly convertible to each other and there is a default template parameter.
- Note
- allocate() throws std::bad_alloc() similarly to the default STL memory allocator. This is necessary - STL functions which allocates memory expects it. Otherwise these functions will try to use the memory, leading to segfaults if memory allocation was not successful.
-
This allocator cannot be used for std::basic_string with RHEL 6/7 because of this bug: https://bugzilla.redhat.com/show_bug.cgi?id=1546704 "Define _GLIBCXX_USE_CXX11_ABI gets ignored by gcc in devtoolset-7"