Re: Need some help understanding array definitions



Ed wrote:
"Elizabeth D Rather" <erather@xxxxxxxxx> wrote in message
news:88idnbPPNOfxr83VnZ2dnUVZ_gydnZ2d@xxxxxxxxxxxxxxxx
dkelvey@xxxxxxxxxxx wrote:
...
Marcel stated that it is not possible to create local
arrays but that is not true. With care, one can create
such arrays on the return stack or in an area of
memory allocated for such local arrays. One would
need to either have error checking or care when
using so as not to over use such space.
One could even setup a dynamicaly allocated spaces,
such as other languages do, with garbage collection and
such.
Yes, but these are definitely advanced strategies, and rarely
appropriate even then. The most advanced Forth programmers I know avoid
doing these things.

But what to do when they're not avoidable?

I can't answer that, as I have trouble imagining such a circumstance.

In Windows using the return stack for temps is, well, very
tempting. M/C programmers use this trick all the time.
Stephen wanted to extend locals to include buffers.
If I recall SwiftForth has words to allocate buffer space
on the return stack, using R@ to get the address.
User-variables (not standard) are fine but aren't dynamic.
There is ALLOCATE but it might be slow.

ALLOCATE is an ok way to get temporary buffer space. It isn't particularly slow. Playing games with the Return Stack isn't portable, and can present reliability issues. And in Windows, you certainly have no limitations on static data space, why not use it?

Perhaps forth does need a return stack buffer allocation
word. The downside - slower than static buffers; care
must be taken to ensure the buffer is properly unwound;
max size is very system dependent; not so viable for
systems with small stacks. OTOH it should take less
effort to implement than a full blown locals scheme.

I'm just not at all persuaded that the need is there.

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."
==================================================
.



Relevant Pages

  • Re: Need some help understanding array definitions
    ... With care, one can create ... In Windows using the return stack for temps is, well, very ... If I recall SwiftForth has words to allocate buffer space ... There is ALLOCATE but it might be slow. ...
    (comp.lang.forth)
  • Re: Need some help understanding array definitions
    ... With care, one can create ... on the return stack, using R@ to get the address. ... There is ALLOCATE but it might be slow. ... ALLOCATE is an ok way to get temporary buffer space. ...
    (comp.lang.forth)
  • Re: Reasons for a buffer or RAM
    ... [buffer not over 16k] ... that noone took this and tried to allocate such a big buffer on the ... > I'm pretty sure that the stack only grows downward a page at a ... than a page size on the stack (subtract more than a page ...
    (alt.lang.asm)
  • Re: [PATCH] Add IPv6 support to TCP SYN cookies
    ... This huge buffer should not be allocated on stack. ... I can replace it will a kmalloc, but for my benefit what's the practical ... we are unable to allocate enough memory, so it can simply drop the ...
    (Linux-Kernel)
  • Re: _strdup deprecated????
    ... determines the size of the buffer to allocate and simply returns a pointer ... I don't much care for the function itself. ...
    (microsoft.public.vc.language)

Loading