Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Has anyone implemented region based memory management in Forth, a practical example would be nice

122 views
Skip to first unread message

mfany...@gmail.com

unread,
Jul 17, 2015, 3:07:45 AM7/17/15
to
Reading through the group topics I noticed a recent thread mentioning region 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 language so I am sort of still stuck in literature as far as this subject is concerned. It would be nice if someone who has done some actually coding in Forth and are willing to share their code so that I can finally get this off my "bucket list" :)

Have a brilliant day , all :)

Elizabeth D. Rather

unread,
Jul 17, 2015, 3:46:32 AM7/17/15
to
How do you define "region based memory management"?

Cheers,
Elizabeth

--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc. +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

Mark Wills

unread,
Jul 17, 2015, 3:52:39 AM7/17/15
to

Elizabeth D. Rather

unread,
Jul 17, 2015, 3:59:24 AM7/17/15
to
Thank you, Mark.

Alex McDonald

unread,
Jul 17, 2015, 10:22:30 AM7/17/15
to
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.


mfany...@gmail.com

unread,
Jul 17, 2015, 11:37:59 AM7/17/15
to
How do you handle fragmentation?

Alex McDonald

unread,
Jul 17, 2015, 12:11:51 PM7/17/15
to
With ALLOT there's no fragmentation, since it can't be freed. The whole
point of a region is to work with it and then toss it away once you're
done. https://en.wikipedia.org/wiki/Region- based_memory_management
0 new messages