且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

std :: sort算法的内存使用情况

更新时间:2023-11-13 23:02:58

标准没有规定标准库算法可以使用的内存,因此该实现通常可以根据需要进行操作.这包括分配堆内存.

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.

但是:

背景是我考虑将一些标准库算法引入到嵌入式环境中,在这种环境中,受控的内存使用至关重要. (尤其是不得使用堆).

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).

实现必须确保其算法能够执行标准定义的功能.这意味着:如果您拥有支持目标环境的C ++编译器,则它必须在上述目标平台上做正确的事情,但是它可以实现目标.

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.