stack

stack — Initializes the stack.

Description

Initializes and sets the size of the global stack.

Syntax

stack  iStackSize

Initialization

iStackSize - size of the stack in bytes.

Performance

Csound implements a single global stack. Initializing the stack with the stack opcode is not required - it is optional, and if not done, the first use of push or push_f will automatically create a stack of 32768 bytes. Otherwise, stack is normally called from the orchestra header, and takes a stack size parameter in bytes (there is an upper limit of about 16 MB). Once set, the stack size is fixed and cannot be changed during performance.

The global stack works in LIFO order: after multiple push calls, pop should be used in reverse order.

Each push or pop operation can work on a "bundle" of multiple variables. When using pop, the number, type, and order of items must match those used by the corresponding push. That is, after a 'push Sfoo, ibar', you must call something like 'pop Sbar, ifoo', and not e.g. two separate 'pop' statements.

push and pop opcodes can take variables of any type (i-, k-, a- and strings). Variables of type 'a' and 'k' are passed at performance time only, while 'i' and 'S' are passed at init time only.

push/pop for a, k, i, and S types copy data by value. By contrast, push_f only pushes a "reference" to the f-signal, and then the corresponding pop_f will copy directly from the original variable to its output signal. For this reason, changing the source f-signal of push_f before pop_f is called is not recommended, and if the instrument instance owning the variable that was passed by push_f is deactivated before pop_f is called, undefined behavior may occur.

Any stack errors (trying to push when there is no more space, or pop from an empty stack, inconsistent number or type of arguments, etc.) are fatal and terminate performance.

See also

pop, push, pop_f and push_f.

Credits

By: Istvan Varga.

2006