Forth中的内存管理 [英] Memory management in Forth

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

问题描述

因此,我只是在学习Forth,并好奇是否有人可以帮助我了解内存管理的总体工作原理.目前,我对C stack-vs-heap范例只有(部分)经验.

据我了解,一个人可以在Dictionary或堆中进行分配.字典是否像C中的堆栈一样更快/更受青睐?但是与C语言不同,它没有作用域和自动堆栈回收,因此我想知道是否仅将字典用于全局数据结构(如果有的话).

就堆而言,它与C差不多吗?堆管理是一个标准的( ANS )概念,还是实现定义的? >

解决方案

它不是Dictionary,也不在堆上-相当于堆的是字典.但是,由于存在一个严格的限制,即它的作用类似于堆栈而不是堆-在字典末尾添加了新单词(通过ALLOT进行分配,并通过FORGET或FREE进行释放(但释放 all 较新的词-表现得更像多个POP).

一种实现可以控制内存布局,从而实现传统的堆(或垃圾回收).一个示例是 用于内存管理的堆数据结构的FORTH实现 (1984).另一个实现是 Quartus Forth的动态内存堆 (2000年). /p>

很多取决于实现或扩展.例如,内存布局通常带有两个块缓冲区(由BLOCKTIB定位),文本输入缓冲区以及该语言的值和低级/原始函数,位于最低部分,位于字典中.中间(向上增长),返回堆栈和参数堆栈位于顶部 1 .

字典上方第一个可用字节的地址由HERE返回(随着字典扩展而变化).

字典(PAD返回的地址)上方还有一个暂存区,用于临时存储数据.暂存区可以视为空闲内存.

首选操作方式是尽可能多地使用堆栈,而不是局部变量或堆.

1 286(关于Forth的特定版本,MMSFORTH)在"FORTH的记忆,词典和词汇"一章中, Forth:文本和参考. Mahlon G. Kelly和Nicholas Spies . ISBN 0-13-326349-5/0-13-326331-2(PBK.). 1986年,Prentice-Hall撰写.

So I'm just learning Forth and was curious if anyone could help me understand how memory management generally works. At the moment I only have (some) experience with the C stack-vs-heap paradigm.

From what I understand, one can allocate in the Dictionary, or on the heap. Is the Dictionary faster/preferred like the stack in C? But unlike in C, there aren't scopes and automatic stack reclamation, so I'm wondering if one only uses the dictionary for global data structures (if at all).

As far as the heap goes, is it pretty much like C? Is heap management a standard (ANS) concept, or is it implementation-defined?

解决方案

It is not Dictionary, or on the heap - the equivalent of the heap is the dictionary. However, with the severe limitation that it acts more like a stack than a heap - new words are added to the end of the dictionary (allocation by ALLOT and freeing by FORGET or FREE (but freeing all newer words - acting more like multiple POPs)).

An implementation can control the memory layout and thus implement a traditional heap (or garbage collection). An example is A FORTH implementation of the Heap Data Structure for Memory Mangement (1984). Another implementation is Dynamic Memory Heaps for Quartus Forth (2000).

A lot is implementation dependent or extensions. For instance, the memory layout is often with the two block buffers (location by BLOCK and TIB), the text input buffer and values and low-level/primitive functions of the language, in the lowest portion, dictionary in the middle (growing upwards) and the return stack and the parameter stack at the top 1.

The address of the first available byte above the dictionary is returned by HERE (it changes as the dictionary expands).

There is also a scratchpad area above the dictionary (address returned by PAD) for temporarily storing data. The scratchpad area can be regarded as free memory.

The preferred mode of operation is to use the stack as much as possible instead of local variables or a heap.

1 p. 286 (about a particular edition of Forth, MMSFORTH) in chapter "FORTH's Memory, Dictionary, and Vocabularies", Forth: A text and a reference. Mahlon G. Kelly and Nicholas Spies. ISBN 0-13-326349-5 / 0-13-326331-2 (pbk.). 1986 by Prentice-Hall.

这篇关于Forth中的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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