许多编程语言运行时环境使用堆栈作为它们的主要存储结构(例如,参见 JVM bytecode to runtime example)。
快速回想一下,我看到了以下优点:
- 结构简单(pop/push),实现起来很简单
- 大多数处理器都针对堆栈操作进行了优化,因此速度非常快
- 内存碎片问题较少,它始终是上下移动内存指针以进行分配,并通过将指针重置为最后一个条目偏移量来释放完整的内存块。
列表是否完整或我遗漏了什么?是否存在根本不使用堆栈进行存储的编程语言运行时环境?
最佳答案
刚刚决定包含一个指向最有洞察力的开发人员之一的链接(和活跃的),热点 JVM 的架构师:
When you compare the speed & power of a CPU executing bytecodes, you'll see lots of hardware complexity around the basic execution issues (I'm skipping on lots of obvious examples, but here's one: the stack layout sucks for wide-issue because of direct stack dependencies).
http://www.azulsystems.com/blog/cliff-click/2010-04-21-un-bear-able
关于java - 编程语言运行时使用堆栈的主要原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4706994/