Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #25396
| Date | 2013-08-25 20:21 +0100 |
|---|---|
| Subject | Relocatable Blocks |
| From | Ian van Breda <igvb@btopenworld.com> |
| Newsgroups | comp.lang.forth |
| Message-ID | <CE4017C0.3A79%igvb@btopenworld.com> (permalink) |
Most modern operating systems make used of one or more heaps to collect transient data items. This is done by means of handles, i.e. indirect addresses, which point to relocatable blocks for access on the heap. This allows the size of a block to be changed, moving the block when necessary, but the handle remains the same. Relocatable blocks are very useful for structures whose size is not known beforehand, particularly for stacks and queues and certain types of object structures. In Mas OS 9 only windows records are kept in non-relocatable blocks; the other data structures are held in relocatable blocks. For embedded systems, relocatable blocks can be accomplished by placing the block in the Forth data space and moving it explicitly when the size is changed but, again, it is necessary to use indirect addressing for reference. I suggest that the equivalent definitions for ALLOCATE, FREE and RESIZE be defined in the standard. NEW-HANDLE ( u -- hndl ior) Attempt to allocate a relocatable block of size u address units on the heap. The initial content of the allocated space is undefined. Attempts to create a free block of the requested size, including compacting the heap zone, if necessary. If the allocation succeeds, ior is returned as zero. If it has not been possible to allocate a block of the required size, ior is the implementation-defined error result code. FREE-HANDLE ( hndl -- ior) Dispose of a relocatable block, given its handle. Returns a zero if the operation was performed correctly, returns a non-zero if there has been an error. RESIZE-HANDLE ( hndl u -- ior) Changes the logical size of the relocatable block, given a handle and required size. Returns zero ior if successful. If it has not been possible to allocate a block of the required size, ior is the implementation-defined result code. I have used relocatable blocks in my Forth dictionary, along the lines outlined in Crafting a Compiler (Fischer, el al). Particularly, allowing the dictionary to be case sensitive or not, as required. An addition, it allows words not use in a running system to be discarded. For my system, there are a fair number of word that are not relevant to application code - various Mac OS Traps, a number of subroutines and a large number of OS data structures - which can be discarded in a precompiled system. There are compiler directives for this: GLOBAL causes definition headers to be marked as visible in a running system up to the next LOCAL; LOCAL (not to be confused with LOCALS| ) which sets a flag that marks subsequent definition headers as used only during compilation up to the next GLOBAL; INVISIBLE discards all LOCAL headers from the dictionary (but not their code!). For example, I have a dictionary of 2480 words but in a running system this drops to 1120 for a fully pre-compiled ANS system (plus other items), from a minimal kernel after applying INVISIBLE. It is important to note that the purpose here is not to reduce memory usage but instead to simplify the dictionary and avoiding cluttering in it up with words not needed in a working system (dictionary entropy/pollution). This means that LOCAL headers are not included on WORDS. I also use a definition that only gives that TASK-WORDS for a compiled application. Also, there is switch that allows WORDS to work either in chronological or alphabetical order. Ian van Breda
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Relocatable Blocks Ian van Breda <igvb@btopenworld.com> - 2013-08-25 20:21 +0100
Re: Relocatable Blocks Paul Rubin <no.email@nospam.invalid> - 2013-08-25 14:04 -0700
Re: Relocatable Blocks Ian van Breda <igvb@btopenworld.com> - 2013-08-29 19:55 +0100
Re: Relocatable Blocks albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-08-26 11:34 +0000
Re: Relocatable Blocks Hans Bezemer <the.beez.speaks@gmail.com> - 2013-08-26 14:58 +0200
Re: Relocatable Blocks Hans Bezemer <the.beez.speaks@gmail.com> - 2013-08-26 15:30 +0200
Re: Relocatable Blocks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-26 14:33 +0000
Re: Relocatable Blocks Ian van Breda <igvb@btopenworld.com> - 2013-08-29 20:22 +0100
Re: Relocatable Blocks Mark Wills <markrobertwills@yahoo.co.uk> - 2013-08-26 07:08 -0700
csiph-web