Skip to content

SecondaryStack

Simon Wright edited this page Sep 20, 2018 · 5 revisions

The secondary stack is what GNAT uses to manage functions which return objects of an indefinite type: for example,

   function F return String;

Desktop GNAT manages the secondary stack in the heap, so that it can be of unbounded size. This implementation, however, manages it by carving out a proportion of each task’s stack; currently this is 10%, but this can be altered globally in System.Parameters (s-parame.adb) in function Secondary_Stack_Size:

   function Secondary_Stack_Size (Stack_Size : Size_Type) return Size_Type
     is ((Stack_Size * 10) / 100);

Up to FSF GCC 8/GNAT CE 2018, if you have a function returning a large indefinite type (a long String, say, or an indefinite array of large objects), you’ll need to allocate a larger stack for the using task:

   task type T
   with
     Storage_Size => 10_000
   is
   end T;

For FSF GCC 8/GNAT CE 2018, you can alternatively specify the size you want:

   task type T
   with
     Secondary_Stack_Size => 10_000
   is
   end T;

in which case the secondary stack is allocated separately from the task's stack.

Note:

  • Storage_Error will be raised if you try to use more secondary stack than is available.
Clone this wiki locally