Re: Declaring local variables inside loop



On Wed, 22 Feb 2006 12:54:50 +0100, Hendrik Maryns
<hendrik_maryns@xxxxxxxxxxxxx> wrote, quoted or indirectly quoted
someone who said :


Now my question is: does it matter that I declare tupleWithSecond
outside the loop? I have the impression that if I leave the first line
out and instead add ?FunctionInputTuple? before the third line, that a
new pointer space is created on the stack for each loop.

all slots on the stack frame for locals are allocated by a single
addition(subtraction) of the stack pointer on entering the method.

The advantage of putting them inside:

1. helps an optimiser. It know they can't be used in any way outside
the loop so it does not need to worry about saving them in ram in
case you jump out the loop.

2. helps others understand your code.


--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.



Relevant Pages

  • Re: I want to learn forth but...
    ... on each pass of the loop. ... deeper in the execution stack. ... faster than even a register bank of any real size. ...
    (comp.lang.forth)
  • Re: DISFAVORED Was: name for 3 PICK finally?
    ... No complication except having a pool for stack variables, ... I felt like it was nice to have a loop ... I also have a defining word called PLURAL which I use to make plurals ... actually need any headerless definitions, ...
    (comp.lang.forth)
  • Re: How would you do this in forth?
    ... then compiles the address as a literal. ... stack so you can do something interesting with it later during run ... and execute it with yield. ... so no more dangerous than BEGIN WHILE THEN or DO LOOP;) ...
    (comp.lang.forth)
  • Re: Toward a Forth thats easier to learn
    ... And yet you're advocating an approach to software that shuts all but the ... the return stack that users use be independent of the loop stack is a ... getting them to understand that loop items are on the return stack), ... and another range that stayed cells. ...
    (comp.lang.forth)
  • Re: Toward a Forth thats easier to learn
    ... return stack before you enter a DO loop and use R@ inside the loop. ... That's why we have -LOOP in Gforth. ... (compilation token) ...
    (comp.lang.forth)