stack
Prev | Deprecated Orchestra Opcodes and GEN Routines | Next

## stack

stack — Initializes the stack. Deprecated.

## Description

Plugin opcode in stackops.

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 'Sbar, ifoo pop', 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.

## Examples

Here is an example of the stack opcode. It uses the file stack.csd.

Example 1327. Example of the stack opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac   ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o stack.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    0dbfs  = 1
    nchnls = 2

    stack 100000

    instr 1

    a1	oscils 0.7, 220, 0
    k1	line 0, p3, 1
            push "blah", 123.45, a1, k1
            push rnd(k1)

    k_rnd	pop
    S01, i01, a01, k01 pop
            printf_i "S01 = '%s', i01 = %g\n", 1, S01, i01
    ktrig	metro 5.0
            printf "k01 = %.3f, k_rnd = %.3f\n", ktrig, k01, k_rnd
            outs a01, a01

    endin
    </CsInstruments>
    <CsScore>

    i 1 0 5
    e
    </CsScore>
    </CsoundSynthesizer>

## See also

pop, push, pop_f and push_f.

Using this opcode is somewhat hackish, as you can read here: http://csound.1045644.n5.nabble.com/passing-a-string-to-a-UDO-td1099284.html

## Credits

By: Istvan Varga.

2006

Deprecated as of version 6.04.

Prev | Up | Next
soundouts | Home | tb