Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::sort algorithms memory usage

I'm wondering whether the standard libraries sorting algorithms (e.g. std::sort) are using the heap memory for sorting.

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

The background is that I consider to introduce some of the standard library algorithms into an embedded environment in which a controlled memory usage is crucial. (especially the heap shall not be used).

Thank you in advance!

like image 376
Andreas Avatar asked Jan 04 '17 23:01

Andreas


Video Answer


1 Answers

What memory the standard library algorithms can use is not mandated by the standard, so the implementation can generally do as it wants. That includes allocating heap memory.

You can check if some specific implementation provides the guarantees you want, but again, in general, you have no control over how the implementation implements its algorithms.


However:

The background is that I consider to introduce some of the standard library algorithms into an embedded environment in which a controlled memory usage is crucial. (especially the heap shall not be used).

The implementation must make sure that its algorithms do what they are supposed to do as defined by the standards. That means: If you have a C++ compiler that supports your target environment, it must do the right thing on said target platform, however it achieves that.

In particular: If your platform does not have a heap, any implementation that supports it must not use the heap.

like image 179
Baum mit Augen Avatar answered Sep 23 '22 06:09

Baum mit Augen