Next: , Previous: swapstack, Up: libstack.a

6.3.2 Implementation of stack checking and extension

The basic principle of stack checking is that the compiler emits special code to check if the stack is large enough whenever there's need for a bigger chunk of stackspace, i.e. at function entry when local arrays are allocated, at the start of blocks with local variable sized arrays and when calling ‘alloca()’. If the needed stackchunk is bigger than the left stackspace the program ends.

Since this special code costs memory and CPU time smaller stackneeds (e.g. when calling library functions) are handled by not really checking against the hard border of the stackframe but against one that leaves a certain amount of stackspace left (See Advanced.). If you like to call functions with a lot of arguments (more than 256 bytes) you should raise this value.

Stack extension builds on the same basic principle but allocates a new stackframe whenever necessary. If this happens at the entry of a function with arguments they have to be copied to the new stackframe so that the function may use them. Since C allows for a variable number of arguments the compiler doesn't always know how many arguments there are. Therefore only a fixed number of bytes is copied. If your functions may have lots of arguments (again more than 256 bytes) you should raise this number.

Since allocation and freeing of memory through OS functions costs a lot of time (while a stack tends to be very dynamic) libnix caches once used stackframes and utilizes them again if necessary. The memory needed for this doesn't accumulate or such but just sticks to a maximum value raised once. This may look like a memory leak (while in fact it isn't). Be prepared for it.