Memory usage std :: sort

I am wondering if standard library sorting algorithms (like std :: sort) use heap memory for sorting.

Is there any reliable source how to find out what type (heap, stack) and how much temporary memory is used by the sorting algorithm or any standard library algorithm in general?

The background is that I am considering introducing some standard library algorithms into an embedded environment in which the use of controlled memory is critical. (especially a bunch should not be used).

Thank you in advance!

+5
source share
1 answer

What kind of memory that standard library algorithms can use is not required by the standard, so implementation can usually be done at will. This includes heap memory allocation.

You can check if any particular implementation provides the guarantees you want, but again, in general, you cannot control how the implementation implements its algorithms.


But:

The background is that I am considering introducing some standard library algorithms into an embedded environment in which the use of controlled memory is critical. (especially a bunch should not be used).

An implementation must ensure that its algorithms do what they need to do, as defined by standards. This means: if you have a C ++ compiler that supports your target environment, it should do the right thing on the specified target platform, but it does.

In particular: if your platform does not have a heap, any implementation that supports it should not use a heap.

+7
source

Source: https://habr.com/ru/post/1262326/


All Articles