3.2.10 DYNAMIC-EXTENT declarations

You can request stack allocation of&rest arguments by usingdynamic-extent declarations. Allocating&rest list structures on a stack rather than in dynamic storage reduces the amount of dynamic memory used by a program and thus reduces the number of garbage collections.

The list of argument values bound to an&rest argument is normally constructed in dynamic storage. When the function that created the list exits, this dynamic storage is not deallocated until the next garbage collection because the list might be stored in a data structure or be bound to a dynamic variable that survives the function call.

Often, however, the&rest argument has dynamic extent, which means that the list is not accessible after the function call that created it exits. The storage allocated to it is therefore not needed after the function call exits. For example, in the following code the &rest argument is only needed to access the components of the list during the execution of the function:

Adynamic-extent declaration informs the Compiler that an &rest argument has dynamic extent and that the storage allocated to it can be released when the function call returns. The Compiler can then generate code that allocates and deallocates the storage for the list on a stack. Lists that are allocated and deallocated on a stack are called stack lists.

You can allocate lists on a stack in the following manner:

Adddynamic-extent declarations for the&rest arguments to be allocated on a stack.

You can declare a stack list&rest argument by using the following declaration:

(declare (dynamic-extent variable))

Make sure stack list allocation is enabled at run-time. Stack list allocation is enabled by default. You can explicitly disable it by calling the functiondisable-stack-lists; you can explicitly enable it by calling the functionenable-stack-lists.

When stack list allocation is enabled, the following code produces a function that sums its fixnum arguments without using dynamic allocation: