Métrologie
Métrologie
MarWin: Did you know... stack overflow
EN

Did you ever had the runtime error message “stack overflow“?


If so, you probably used large arrays. There is an example below that should produce this error message (PROGRAM StackSize). There are two solutions for this (and they can be combined):


Solution 1: Increase the stack size

Start->coreconfig.exe:

In MarWin 8 you may increase the stack size up to 2 GB. But for a price: If your computer is running any other program or another MarWin instance, you might slow down your computer considerably.


Solution 2: local blocks

If possible, put the large arrays into local blocks. A block is encapsulated inside structures like loops (REPEAT/FOR/WHILE) or subroutines. Be aware that the arrays cannot be accessed outside the blocks. See examples below.


// This program should generate a runtime error “stack overflow”
PROGRAM StackSize
BEGIN
                VAR INT N = 2000000
                VAR ARRAY DOUBLE x[N],y[N],z[N],c[N]
                GET PROFILE VALUES (PROF="./helix_25.prf", START=1, END_=N,
                               X=x,
                               Y=y,
                               Z=z,
                               C=c)
                // do something with x,y,z,c
END

// This program should NOT generate a runtime error “stack overflow”
PROGRAM StackSize2
BEGIN
                VAR INT N = 2000000
                REPEAT
                               VAR ARRAY DOUBLE x[N]
                               GET PROFILE VALUES (PROF="./helix_25.prf", START=1, END_=N, X=x)
                UNTIL 1
                REPEAT
                               VAR ARRAY DOUBLE y[N]
                                GET PROFILE VALUES (PROF="./helix_25.prf", START=1, END_=N, Y=y)
                UNTIL 1
                REPEAT
                               VAR ARRAY DOUBLE z[N]
                               GET PROFILE VALUES (PROF="./helix_25.prf", START=1, END_=N, Z=z)
                UNTIL 1
                REPEAT
                               VAR ARRAY DOUBLE c[N]
                               GET PROFILE VALUES (PROF="./helix_25.prf", START=1, END_=N, C=c)
                UNTIL 1
END