A repeat procedure is a procedure in which a single copy of a program code can be used by several users for the same period of time. Red has two key aspects: the program code cannot change itself, and local data for each user must be stored separately.
In a common system, re-allocation allows for more efficient use of main memory: one copy of the program code is stored in main memory, but several procedures can invoke a procedure. Thus, the repeated procedure must have a constant part (instructions that make up the procedure) and a temporary part (pointer back to the calling program, as well as memory for local variables used by the program).
Each execution instance, called procedure activation, executes the code in the constant part, but must have its own copy of local variables and parameters. The temporary part associated with a particular activation is called an activation record.
The most convenient way to support reentrant procedures is through the stack. When a repeated procedure is called, the activation record becomes part of the stack frame created when the procedure was called
user731914
source share