MacroPackage: cgToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

with-positions-and-boxes

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

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

position-variables and box-variables are just symbols which name positions in the body of the macro. Use nmake-position to supply the positions with x and y values and nmake-box to supply the boxes with left, top, right, and bottom 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, boxp, 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-box 0 0 10 10), is now strongly discouraged due to potential re-entrancy conflicts.

Example:

(defun is-pos-in-box (x y left top right bottom)
  ;; Avoids consing a position and a box.
  (with-positions-and-boxes (tpos) (tbox)
    (inside-box-p (nmake-position tpos x y)
                  (nmake-box tbox left top right bottom))))
;; Load and compile, and then:
cg-user(35): (time (is-pos-in-box 10 20 15 15 30 30))
; cpu time (non-gc) 0.000000 sec user, 0.000000 sec system
; cpu time (gc)     0.000000 sec user, 0.000000 sec system
; cpu time (total)  0.000000 sec user, 0.000000 sec system
; real time  0.000000 sec 
; space allocation:
;  0 cons cells, 0 other bytes, 0 static bytes
; Page Faults: major: 0 (gc: 0), minor: 0 (gc: 0)
nil
cg-user(36): (is-pos-in-box 10 20 5 5 30 30)
t
cg-user(37): 

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


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

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version