Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "Controlling Application Stack"
Steven Solie (talk | contribs) |
Steven Solie (talk | contribs) |
||
Line 10: | Line 10: | ||
<syntaxhighlight> |
<syntaxhighlight> |
||
− | static const char |
+ | static const char USED min_stack[] = "$STACK:102400"; |
int main() |
int main() |
||
Line 20: | Line 20: | ||
This adds a stack cookie of 100kB (102400 bytes). |
This adds a stack cookie of 100kB (102400 bytes). |
||
− | The |
+ | {{Note|title=The USED macro|text=The macro '''USED''' in the code sample translates into '''__attribute__((used))''' when using GCC. Other compilers may have their own syntax. The '''USED''' attribute is necessary otherwise the linker may remove your stack cookie because it is not accessed directly by any code in your application.}} |
{{Note|The enforced minimum system stack size is always respected despite what was is put in your stack cookie.}} |
{{Note|The enforced minimum system stack size is always respected despite what was is put in your stack cookie.}} |
Latest revision as of 15:20, 29 May 2013
Applications running on AmigaOS must estimate the maximum amount of stack they will use. This is because AmigaOS does not have any form of automatic stack enlargement. Any application which exceeds its stack boundaries will cause indeterminate system behaviour.
Enforced Minimum Stack Size
A minimum stack size of X? bytes is enforced for all Tasks and Processes.
Stack Cookie
Application programmers are strongly encouraged to use a stack cookie which informs the system what the absolute minimum stack size of your application is. For example,
static const char USED min_stack[] = "$STACK:102400"; int main() { // ... }
This adds a stack cookie of 100kB (102400 bytes).
The USED macro |
---|
The macro USED in the code sample translates into __attribute__((used)) when using GCC. Other compilers may have their own syntax. The USED attribute is necessary otherwise the linker may remove your stack cookie because it is not accessed directly by any code in your application. |
Note |
---|
The enforced minimum system stack size is always respected despite what was is put in your stack cookie. |
Minimum Recommended GUI Application Stack Size
Applications which use BOOPSI classes and especially window.class will require a large amount of stack. The minimum recommended stack size for any application with a GUI is 80000 bytes. If your application happens to run low on stack then Intuition will swap out your stack for a larger one before processing every message. Such stack swapping is visible to application programmers by setting a debug level of 5 or greater. You can avoid this performance penalty by using a large enough stack.