2

In some systems, the stack grows in upward direction whereas the heap grows in downward direction and in some systems, the stack grows in downward direction and the heap grows in upward direction. But, Which is the best design ? Are there any programming advantages for any of those two specific designs ? Which is most commonly used and why has it not been standardized to follow a single approach ? Are they helpful/targeted for certain specific scenarios. If yes, what are they ?

4

3 回答 3

1

堆只会在非常幼稚的实现中朝一个方向“增长”。正如 Paul R. 所提到的,堆栈增长的方向是由硬件定义的——在 Intel CPU 上,它总是朝着更小的地址“即‘向上’”

于 2010-07-30T19:00:38.530 回答
0

我读过 Miro Samek 和其他各种嵌入式专家的作品,似乎他们不赞成在嵌入式系统上进行动态分配。这可能是由于复杂性和内存泄漏的可能性。如果您有一个绝对不会失败的项目,您可能希望避免使用 Malloc,因此堆会很小。其他非关键任务系统可能正好相反。我不认为会有一个标准的方法。

于 2010-07-30T18:59:55.143 回答
0

也许它只是依赖于处理器:它是否支持堆栈向上或向下?

于 2010-07-30T19:00:16.017 回答