c++memorystlc++17stl-algorithm

Which Algorithms in the standard algorithm library allocate and is there a way to specify how this allocation occurs?


I'd like to make more use of standard algorithms but have some pretty tight requirements for controlling memory allocation.

Is there a comprehensive list of which algorithms in allocate?
Also, is there anyway to control how this allocation occurs? Is the only option overriding global new? Does that actually work if linking statically? Prior to C++17 it appears that all allocations went through std::get_temporary_buffer() to allocate memory but this seems to deprecated in C++17. What replaces this?


Solution

  • Looks like the only way to get control of the allocations is through overriding global new. See here, section "Global replacements"

    http://en.cppreference.com/w/cpp/memory/new/operator_new

    Since this works at link time, it means that each dll will have to link a translation unit with overridden global new/delete. How exactly this maps to any particular allocation strategy is probably beyond the scope of this question.

    The other answers here specify which algorithms attempt to use temporaries.

    stable_partition, stable_sort, and inplace_merge