Component_malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
More...
template<class T = void *>
class Component_malloc_allocator< T >
Component_malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
This allows for P_S instrumentation of memory allocation done internally by STL container classes in components.
Example usage: vector<int, Component_malloc_allocator<int>> v((Component_malloc_allocator<int>(PSI_NOT_INSTRUMENTED)));
If the type is complicated, you can just write Component_malloc_allocator<>(psi_key) as a shorthand for Component_malloc_allocator<My_complicated_type>(psi_key), as all Component_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"