std :: sort算法的内存使用情况 [英] std::sort algorithms memory usage

查看:79
本文介绍了std :: sort算法的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道标准库的排序算法(例如std :: sort)是否正在使用堆内存进行排序.

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

提前谢谢!

推荐答案

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

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.

这篇关于std :: sort算法的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆