pForth memory management mystery

43 views
Skip to first unread message

Craig Lindley

unread,
Sep 7, 2018, 10:38:51 AM9/7/18
to pforthdev
Hello all,

I've been a fan of forth for a long time after using it at Rolm corporation for testing big PBX switches, at Sun where it was used as the bootloader for all their computers and at JPL where I used it for some testing on the Galileo spacecraft. Recently I have renewed my interest in forth but have found programming tedious as compared to modern computer languages. When I came upon pForth with named parameters and local variables it blew my mind and made forth programming fun again. Thanks for every ones hard work to make that happen.

Anyway. I'm finishing my port of pForth to an ESP32-wrover-kit and everything is working well. I have created a bunch of custom words dealing with SPI and other things so I decided to also create a word that would return the free heap size. What I noticed I cannot explain but I hope someone here can. When pForth starts up I see it call my AllocMem function three times 

AllocMem: 44
AllocMem: 38684
AllocMem: 85568

I then call my free heap word and get a number. So far so good. I then compile a bunch of forth code which results in over 127 words added to the dictionary. The mystery is when I call my free heap word again it reports exactly the same heap free memory as it did before I compiled.

Are one of the above allocations creating a pool for new definitions ? If I compiled a lot more code would another large allocation occur for a new pool?

Thanks

Craig Lindley




Phil Burk

unread,
Sep 8, 2018, 6:50:28 PM9/8/18
to pforthdev
Hello Craig,

I'm glad you like pForth.

Compiling Forth words does not require allocating memory from the heap. It just allocates memory in the Forth dictionary that was already allocated from the heap.

Enter MAP to see how pForth is using memory.

> Are one of the above allocations creating a pool for new definitions ?

Yes. Memory for names and for code are allocated separately. This allows you to discard the names, theoretically.

> If I compiled a lot more code would another large allocation occur for a new pool?

No. Not automatically. When you notice you need more room, just increase CODE_SIZE or HEADERS-SIZE, then 

    c" pforth.dic" SAVE-FORTH
    BYE

then relaunch pForth and enter MAP to see if it worked.

Phil Burk






--
You received this message because you are subscribed to the Google Groups "pforthdev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pforthdev+...@googlegroups.com.
To post to this group, send email to pfor...@googlegroups.com.
Visit this group at https://groups.google.com/group/pforthdev.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages