Macro | Package: cg | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 10.1 Unrevised from 10.0 to 10.1. 10.0 version

## with-positions

Arguments: ( &rest position-variables) &body body

This macro and the related with-boxes and with-positions-and-boxes stack-allocate position and/or `box` objects to provide temporary objects without consing, thereby possibly reducing the time spent garbage collecting.

position-variables are just symbols which name positions in the body of the macro. Use nmake-position to supply them with `x` and `y` values (see the example below).

The objects are valid only through the dynamic extent of the macro call, and unpredictable errors may occur if they are referenced afterward. Further, functions such as typep and positionp that query the type of an object should not be used on objects created by this macro. Type information for such objects is sacrificed to achieve the non-consing efficiency of stack allocation, and the return values from such type-checking calls are undefined.

Note that now that Common Graphics is multithreaded, the use of the alternative technique of placing position and box constants in source code via the #. reader macro, as in `#.(make-position 0 0)`, is now strongly discouraged due to potential re-entrancy conflicts.

Example:

    (defun draw-diagonal-in-box (window box)
      ;; Avoids consing positions, as when calling box-top-left
      (with-positions (tpos1 tpos2)
        (draw-line window
          (nmake-position tpos1 (box-left box)(box-top box))
          (nmake-position tpos2 (box-right box)(box-bottom box)))))

See About using multiple threads in the IDE in cgide.htm.

Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

|  | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 10.1 Unrevised from 10.0 to 10.1. 10.0 version