Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Controlling Application Stack"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
(Created page with "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 app...")
 
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
   
 
<syntaxhighlight>
 
<syntaxhighlight>
static const char __attribute__((used)) min_stack[] = "$STACK:102400";
+
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 GCC '''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|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 it put in your stack cookie.}}
+
{{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 =
 
= Minimum Recommended GUI Application Stack Size =

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.