on 17/07/2015 08:07:43, wrote:
> Reading through the group topics I noticed a recent thread mentioning
> regio n based memory management which sort of got me a little bit
> excited to see that some work had been done towards leveraging this
> technique in the Forth language.
>
> I have always liked the idea but I have never implemented it in any
> languag e so I am sort of still stuck in literature as far as this
> subject is conce rned. It would be nice if someone who has done some
> actually coding in Fort h and are willing to share their code so that
> I can finally get this off my "bucket list" :)
>
> Have a brilliant day , all :)
>
I have, and it's pretty simple. There are additional words IN-xxx where
xxx is a region name. So
IN-APP the usual data space
IN-SYS used for headers and the like
IN-CODE for code (Intel chips like their data and code to be separated by
a distance)
These are allocated from a fixed data space.
IN-LOC for locals
IN-MALLOC for dynamic
and so on; these are allocated from stack or dynamically allocated memory
respectively. Supporting words include GET-SECTION SWAP-SECTION and
SET-SECTION to more intimately manage memory.
There are equivalent INIT-MALLOC and INIT-LOC words to (re)initialize a
region or throw it away by asking for zero space. There are no INITs for
APP CODE and SYS because they are permanent space.
STC Experimental 32bit: 0.06.08 Build: 334
mem
Area Address Total Used Free
-------------------------------------------------
*loc-c 014B9330 4,096 0 4,096
*loc-d 014B8330 4,096 0 4,096
code 00401000 4,194,304 111,066 4,083,238
app 00801000 4,194,304 17,160 4,177,144
sys 00C01000 4,194,304 83,416 4,110,888
-------------------------------------------------
Total 211,642
ok
The CODE APP and SYS spaces look very large at 4MB, but thet are not yet
allocated, simply reserved space. CODE is followed by APP is followed by
SYS as can be seen by the addresses. The * spaces are LOCALs code and
data respectively; they're transient and carved out of the return stack.
IN-xxx or SET-SECTION affects the following words; HERE ALLOT C, , ALIGN
and some non-standard memory words B, 2, ALLOT&ZERO etc.