Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!usc!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!MITCH.ENG.SUN.COM!wmb From: wmb@MITCH.ENG.SUN.COM Newsgroups: comp.lang.forth Subject: Re: Files VS Blocks, a compromise Message-ID: <9010191326.AA15531@ucbvax.Berkeley.EDU> Date: 19 Oct 90 02:09:12 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: wmb%MITCH.ENG.SUN.COM@SCFVM.GSFC.NASA.GOV Organization: The Internet Lines: 41 > 1. Make allot a deferred word. Whenever a programmer develops You need to defer HERE along with ALLOT . Unfortunately, Forth's ALLOT is poorly conceived, because you have to get the address with HERE *before* you tell ALLOT how much data you need. This pretty much kills the possibility of implementing ALLOT with MALLOC , constraining the data space to be contiguous. In all my recent code, I declare data structures with: BUFFER: \ name ( size -- ) ( Child: -- adr ) Example: 100 BUFFER: FOO FOO 100 44 FILL The simplest implementation is: : buffer: \ name ( #bytes -- ) create allot ; A more sophisticated implementations might look like: : buffer: \ name ( #bytes -- ) create allocate-memory , does> @ ; Another variation, which could be SAVE-FORTH'ed would link all buffers into a static chain and automatically allocate their memory at startup time. The variation I use in the Sun firmware automatically allocates the memory the first time the data structure is accessed. Which definition of BUFFER: to use depends on the system constraints (ROM vs. RAM, serially-reusable or not, etc). Applications are insensitive to the implementation of BUFFER: . Mitch