5 Storage Management in Common Lisp

5.5 Reference pages

change-memory-management Function

Syntax:change-memory-management &key :growth-limit :growth-rate :expand :expand-p :reclamation-ratio :reserved-growth-rate :expand-reserved :reserved-dynamic :help

The functionchange-memory-management alters the parameters that affect storage allocation.

The following keyword arguments can be specified:

This keyword argument specifies the maximum size of memory in segments. A Lisp segment is 64 kilobytes.

This keyword argument specifies the number of dynamic segments that are added to each dynamic semi-space whenever memory is expanded.

This keyword argument forces an immediate expansion of each semi-space of dynamic memory by the specified number of segments. The expansion cannot exceed the maximum size specified by the:growth-limit keyword argument.

A value oft for:expand-p specifies that rather than performing a garbage collection, memory should be expanded at the next point at which additional storage is required.

This keyword argument sets the desired ratio of free dynamic storage to total dynamic storage and is specified as a fraction between 0.0 and 1.0.

This keyword argument specifies the number of reserved segments that are added to the reserved area whenever the reserved area is expanded.

This keyword argument forces an immediate expansion of the reserved area by the specified number of segments.

This keyword argument specifies the number of bytes that are reserved at the end of dynamic space for use in performing the operation specified by the variable*gc-silence*. The default value is 1024 bytes.

This keyword argument provides a brief description of the keyword argument options.

> (room t)
;;; 1030 words [4120 bytes] of dynamic storage in use.
;;; 457464 words [1829856 bytes] of free storage available 
;;; before a GC. 915958 words [3663832 bytes] of free 
;;; storage available if GC is disabled.
;;; Semi-space Size: 1792K bytes [28 segments]
;;; Current Dynamic Area: Dynamic-0-Area
;;; GC Status: Enabled
;;; Reserved Free Space: 3776K bytes [59 segments]
;;; Memory Growth Limit: 32768K bytes [512 segments], total
;;; Memory Growth Rate: 256K bytes [4 segments]
;;; Reclamation Ratio: 33% desired free after garbage collection
;;; Area Information: 
;;; Name                        Size [used/allocated]
;;; ----                        ----
;;; Ephemeral Level 0           9K/512K bytes,     1/8 segments
;;; Ephemeral Level 1           0K/640K bytes,     0/10 segments
;;; Ephemeral Level 2           0K/640K bytes,     0/10 segments
;;; Ephemeral Odd-level OSP     0K/512K bytes,     0/8 segments
;;; Ephemeral Even-level OSP    0K/640K bytes,     0/10 segments
;;; Dynamic-0-Area              5K/1791K bytes,    1/28 segments
;;; Dynamic-1-Area              0K/1792K bytes,    0/28 segments 
;;; Discardable-Static-Area     2K/64K bytes,      1/1 segment
;;; Discardable-Read-Write-Area 588K/640K bytes,   10/10 segments
;;; Foreign Area                37K/64K bytes,     1/1 segment
;;; Static-Area                 523K/576K bytes,   9/9 segments
;;; Read-Write-Area             703K/704K bytes,   11/11 segments
;;; Readonly-Pointer-Area       1144K/1152K bytes, 18/18 segments
;;; Readonly-Non-Pointer-Area   3770K/3776K bytes, 59/59 segments
NIL

> (change-memory-management :growth-limit 300 :growth-rate 16 :reclamation-ratio 0.25) T

> (room t) ;;; 1106 words [4424 bytes] of dynamic storage in use. ;;; 457388 words [1829552 bytes] of free storage available ;;; before a GC. 915882 words [3663528 bytes] of free ;;; storage available if GC is disabled. ;;; Semi-space Size: 1792K bytes [28 segments] ;;; Current Dynamic Area: Dynamic-0-Area ;;; GC Status: Enabled ;;; Reserved Free Space: 3776K bytes [59 segments] ;;; Memory Growth Limit: 19200K bytes [300 segments], total ;;; Memory Growth Rate: 1024K bytes [16 segments] ;;; Reclamation Ratio: 25% desired free after garbage collection ;;; Area Information: ;;; Name Size [used/allocated] ;;; ---- ---- ;;; Ephemeral Level 0 10K/512K bytes, 1/8 segments ;;; Ephemeral Level 1 0K/640K bytes, 0/10 segments ;;; Ephemeral Level 2 0K/640K bytes, 0/10 segments ;;; Ephemeral Odd-level OSP 0K/512K bytes, 0/8 segments ;;; Ephemeral Even-level OSP 0K/640K bytes, 0/10 segments ;;; Dynamic-0-Area 5K/1791K bytes, 1/28 segments ;;; Dynamic-1-Area 0K/1792K bytes, 0/28 segments ;;; Discardable-Static-Area 2K/64K bytes, 1/1 segment ;;; Discardable-Read-Write-Area 588K/640K bytes, 10/10 segments ;;; Foreign Area 37K/64K bytes, 1/1 segment ;;; Static-Area 523K/576K bytes, 9/9 segments ;;; Read-Write-Area 703K/704K bytes, 11/11 segments ;;; Readonly-Pointer-Area 1144K/1152K bytes, 18/18 segments ;;; Readonly-Non-Pointer-Area 3770K/3776K bytes, 59/59 segments NIL

dynamic-gc Function

Syntax:dynamic-gc

The functiondynamic-gc replaces the old functiongc. It invokes the Dynamic Garbage Collector.

The function returns three values: the amount of dynamic storage in use, the amount of free dynamic storage available before a garbage collection, and the amount of free dynamic storage available if the Dynamic Garbage Collector were disabled. These numbers are displayed in thegc message when the variable*gc-silence* is set tonil, which is the default.

> (room)
;;; 684 words [2736 bytes] of dynamic storage in use.
;;; 523346 words [2093384 bytes] of free storage available before a GC.
;;; 1047376 words [4189504 bytes] of free storage available if GC is disabled.
T

> (dynamic-gc) ;;; GC: 612 words [2448 bytes] of dynamic storage in use. ;;; 523674 words [2094696 bytes] of free storage available before a GC. ;;; 1047960 words [4191840 bytes] of free storage available if GC is disabled. 2576 2093544 4189664

> (room) ;;; 644 words [2576 bytes] of dynamic storage in use. ;;; 523386 words [2093544 bytes] of free storage available before a GC. ;;; 1047416 words [4189664 bytes] of free storage available if GC is disabled. T

See Also: gc

egc-off Function

Syntax:egc-off

The functionegc-off disables ephemeral garbage collection.

See Also: egc-on

egc-on Function

Syntax:egc-on

The functionegc-on enables ephemeral garbage collection.

Dynamic garbage collection must be enabled to turn on ephemeral garbage collection.

To use compiled code with ephemeral garbage collection, the code must be compiled by calling the functioncompile,compile-file, orcompiler-options with the value of the:egc keyword argument specified ast. If you attempt to load incompatible code while the Ephemeral Garbage Collector is running or if you enable the Ephemeral Garbage Collector while you are running incompatible code, a continuable error is signaled.

See Also: compile , compile-file , compiler-options , egc-off ,egc-options

egc-options Function

Syntax:egc-options &key :level-sizes :ephemeral-size-limit

The functionegc-options determines the configuration of the ephemeral levels.

The:level-sizes keyword argument determines the number and size of the ephemeral storage levels. The value of the argument is a list of numbers; the length of the list determines the number of ephemeral levels, and each element of the list determines the size, in segments, of the corresponding level. By default, there are three ephemeral levels: level 0 is 8 segments large, level 1 is 10 segments, and level 2 is 10 segments.

The:ephemeral-size-limit keyword argument determines the size, in fixnum words, of the largest object that can be allocated in an ephemeral level. Any object that is larger than this limit is allocated in the current dynamic area. The value of this argument must be less than 8192 words; the default value is 4096 words. A change to the argument value takes effect immediately.

The combined sizes of the ephemeral levels cannot exceed the size of one dynamic semi-space. If you try to expand ephemeral space beyond this limit, Lisp allocates either fewer levels than requested or smaller levels or both. To expand ephemeral space beyond the current size of one semi-space, you must first expand dynamic space by calling the functionchange-memory-management. Then callegc-options again to specify the number of ephemeral levels.

If the functionegc-options is called with no arguments, it returns a list of the current parameter settings:

> (egc-options)
((:LEVEL-SIZES 8 10 10) (:ACTUAL-SIZES 8 10 10) 
(:EPHEMERAL-SIZE-LIMIT . 4096))

;;; Increase the size of ephemeral space to 40 segments. > (egc-options :level-sizes '(10 10 10 10)) ;;; Disabling ephemeral garbage collection. ;;; Enabling ephemeral garbage collection. NIL

;;; This example assumes that the semi-space size is 32 segments. ;;; Therefore, the requested increase exceeds the size of one ;;; dynamic semi-space, and Lisp allocates only 32 segments. > (egc-options) ((:LEVEL-SIZES 10 10 10 10) (:ACTUAL-SIZES 8 8 8 8) (:EPHEMERAL-SIZE-LIMIT . 4096))

;;; Expand dynamic memory by 8 segments. > (change-memory-management :expand 8) ;;; Expanding Dynamic Memory T

;;; Note that expanding dynamic memory does not affect ;;; the size of ephemeral space. > (egc-options) ((:LEVEL-SIZES 10 10 10 10) (:ACTUAL-SIZES 8 8 8 8) (:EPHEMERAL-SIZE-LIMIT . 4096))

;;; Specify the desired ephemeral configuration again. > (egc-options :level-sizes '(10 10 10 10)) ;;; Disabling ephemeral garbage collection. ;;; Enabling ephemeral garbage collection. NIL

> (egc-options) ((:LEVEL-SIZES 10 10 10 10) (:ACTUAL-SIZES 10 10 10 10) (:EPHEMERAL-SIZE-LIMIT . 4096))

See Also: egc-state

egc-state Function

Syntax:egc-state

The functionegc-state returns information about the current state of the ephemeral levels.

This function returns a list of dotted pairs that specify the amount of available space in each ephemeral level. The dotted pairs have the form(used-words . available-words). The function returnsnil if ephemeral garbage collection is disabled.

> (egc-state)
((192 . 524088) (0 . 655352) (0 . 655352))

> (ephemeral-gc) NIL

> (egc-state) ((72 . 524208) (144 . 655208) (0 . 655352))

ephemeral-gc Function

Syntax:ephemeral-gc&optional force-to-dynamic

The functionephemeral-gc explicitly empties the ephemeral levels by calling the Ephemeral Garbage Collector. You can use this function to explicitly delay the next garbage collection.

When called with no arguments, this function empties ephemeral level 0 by causing an ephemeral garbage collection. If the ephemeral garbage collection fills another ephemeral level, storage in the filled level is also reclaimed.

If the value of the optional force-to-dynamic argument ist, all of the ephemeral levels are emptied into dynamic space.

See Also: gc

gc Function

Syntax:gc

The functiongc invokes both the Dynamic Garbage Collector and the Ephemeral Garbage Collector.

The function returns three values: the amount of dynamic storage in use, the amount of free dynamic storage available before a garbage collection, and the amount of free dynamic storage available if the Dynamic Garbage Collector were disabled. These numbers are displayed in thegc message when the variable*gc-silence* is set tonil, which is the default.

> (room)
;;; 792 words [3168 bytes] of dynamic storage in use.
;;; 523238 words [2092952 bytes] of free storage available before a GC. 
;;; 1047268 words [4189072 bytes] of free storage available if GC is disabled.
T

> (gc) ;;; GC: 612 words [2448 bytes] of dynamic storage in use. ;;; 523674 words [2094696 bytes] of free storage available before a GC. ;;; 1047960 words [4191840 bytes] of free storage available if GC is disabled. 2576 2093544 4189664

> (room) ;;; 644 words [2576 bytes] of dynamic storage in use. ;;; 523386 words [2093544 bytes] of free storage available before a GC. ;;; 1047416 words [4189664 bytes] of free storage available if GC is disabled. T

See Also: ephemeral-gc, dynamic-gc, *gc-silence*

gc-off Function

Syntax:gc-off&optional no-reconsideration

The functiongc-off disables dynamic garbage collection. If ephemeral garbage collection is on, it is also disabled.

The optional no-reconsideration argument controls whether disabling dynamic garbage collection causes periodic reconsideration of the issue. If the value of the argument ist, you can use all the available storage without being asked to reconsider. The default value isnil.

IfDynamic-1-Area is the current dynamic area, a dynamic garbage collection occurs whengc-off is called.

> (room t)
;;; 1404 words [5616 bytes] of dynamic storage in use.
;;; 784770 words [3139080 bytes] of free storage available 
;;; before a GC. 1570944 words [6283776 bytes] of free 
;;; storage available if GC is disabled.
;;; Semi-space Size: 3072K bytes [48 segments]
;;; Current Dynamic Area: Dynamic-1-Area
;;; GC Status: Enabled
;;; Reserved Free Space: 3712K bytes [58 segments]
;;; Memory Growth Limit: 32768K bytes [512 segments], total
;;; Memory Growth Rate: 256K bytes [4 segments]
;;; Reclamation Ratio: 33% desired free after garbage collection
;;; Area Information: 
;;; Name                        Size [used/allocated]
;;; ----                        ----
;;; Ephemeral Level 0           1K/512K bytes,     1/8 segments
;;; Ephemeral Level 1           1K/640K bytes,     1/10 segments
;;; Ephemeral Level 2           0K/640K bytes,     0/10 segments
;;; Ephemeral Odd-level OSP     0K/512K bytes,     0/8 segments
;;; Ephemeral Even-level OSP    0K/640K bytes,     0/10 segments
;;; Dynamic-0-Area              0K/3072K bytes,    0/48 segments
;;; Dynamic-1-Area              6K/3071K bytes,    1/48 segments
;;; Discardable-Static-Area     2K/64K bytes,      1/1 segment
;;; Discardable-Read-Write-Area 653K/704K bytes,   11/11 segments
;;; Foreign Area                37K/64K bytes,     1/1 segment
;;; Static-Area                 523K/576K bytes,   9/9 segments
;;; Read-Write-Area             703K/704K bytes,   11/11 segments
;;; Readonly-Pointer-Area       1144K/1152K bytes, 18/18 segments
;;; Readonly-Non-Pointer-Area   3770K/3776K bytes, 59/59 segments
> (gc-off)
;;; GC: 1372 words [5488 bytes] of dynamic storage in use.
;;; 785058 words [3140232 bytes] of free storage available 
;;; before a GC. 1571488 words [6285952 bytes] of free 
;;; storage available if GC is disabled.
;;; Disabling ephemeral garbage collection.
T

> (room t) ;;; 1444 words [5776 bytes] of dynamic storage in use. ;;; 1571418 words [6285672 bytes] of free storage available ;;; before a GC. 1571418 words [6285672 bytes] of free ;;; storage available if GC is disabled. ;;; Semi-space Size: 3072K bytes [48 segments] ;;; Current Dynamic Area: Dynamic-0-Area ;;; GC Status: Disabled ;;; Reserved Free Space: 6656K bytes [104 segments] ;;; Memory Growth Limit: 32768K bytes [512 segments], total ;;; Memory Growth Rate: 256K bytes [4 segments] ;;; Reclamation Ratio: 33% desired free after garbage collection ;;; Area Information: ;;; Name Size [used/allocated] ;;; ---- ---- ;;; Dynamic-0-Area 6K/4672K bytes, 1/73 segments ;;; Dynamic-1-Area 0K/3072K bytes, 0/48 segments ;;; Discardable-Static-Area 2K/64K bytes, 1/1 segment ;;; Discardable-Read-Write-Area 653K/704K bytes, 11/11 segments ;;; Foreign Area 37K/64K bytes, 1/1 segment ;;; Static-Area 523K/576K bytes, 9/9 segments ;;; Read-Write-Area 703K/704K bytes, 11/11 segments ;;; Readonly-Pointer-Area 1144K/1152K bytes, 18/18 segments ;;; Readonly-Non-Pointer-Area 3770K/3776K bytes, 59/59 segments NIL

See Also: egc-on

gc-on Function

Syntax:gc-on

This function enables dynamic garbage collection.

> (gc-off)
;;; Disabling ephemeral garbage collection.
T

> (room t) ;;; 1650 words [6600 bytes] of dynamic storage in use. ;;; 1571212 words [6284848 bytes] of free storage available ;;; before a GC. 1571212 words [6284848 bytes] of free ;;; storage available if GC is disabled. ;;; Semi-space Size: 3072K bytes [48 segments] ;;; Current Dynamic Area: Dynamic-0-Area ;;; GC Status: Disabled ;;; Reserved Free Space: 6656K bytes [104 segments] ;;; Memory Growth Limit: 32768K bytes [512 segments], total ;;; Memory Growth Rate: 256K bytes [4 segments] ;;; Reclamation Ratio: 33% desired free after garbage collection ;;; Area Information: ;;; Name Size [used/allocated] ;;; ---- ---- ;;; Dynamic-0-Area 7K/4672K bytes, 1/73 segments ;;; Dynamic-1-Area 0K/3072K bytes, 0/48 segments ;;; Discardable-Static-Area 2K/64K bytes, 1/1 segment ;;; Discardable-Read-Write-Area 653K/704K bytes, 11/11 segments ;;; Foreign Area 37K/64K bytes, 1/1 segment ;;; Static-Area 523K/576K bytes, 9/9 segments ;;; Read-Write-Area 703K/704K bytes, 11/11 segments ;;; Readonly-Pointer-Area 1144K/1152K bytes, 18/18 segments ;;; Readonly-Non-Pointer-Area 3770K/3776K bytes, 59/59 segments NIL

> (gc-on) T

> (egc-on) ;;; Enabling ephemeral garbage collection. T

> (room t) ;;; 2324 words [9296 bytes] of dynamic storage in use. ;;; 783850 words [3135400 bytes] of free storage available ;;; before a GC. 1570024 words [6280096 bytes] of free ;;; storage available if GC is disabled. ;;; Semi-space Size: 3072K bytes [48 segments] ;;; Current Dynamic Area: Dynamic-0-Area ;;; GC Status: Enabled ;;; Reserved Free Space: 3712K bytes [58 segments] ;;; Memory Growth Limit: 32768K bytes [512 segments], total ;;; Memory Growth Rate: 256K bytes [4 segments] ;;; Reclamation Ratio: 33% desired free after garbage collection ;;; Area Information: ;;; Name Size [used/allocated] ;;; ---- ---- ;;; Ephemeral Level 0 1K/512K bytes, 1/8 segments ;;; Ephemeral Level 1 0K/640K bytes, 0/10 segments ;;; Ephemeral Level 2 0K/640K bytes, 0/10 segments ;;; Ephemeral Odd-level OSP 0K/512K bytes, 0/8 segments ;;; Ephemeral Even-level OSP 0K/640K bytes, 0/10 segments ;;; Dynamic-0-Area 10K/3071K bytes, 1/48 segments ;;; Dynamic-1-Area 0K/3072K bytes, 0/48 segments ;;; Discardable-Static-Area 2K/64K bytes, 1/1 segment ;;; Discardable-Read-Write-Area 653K/704K bytes, 11/11 segments ;;; Foreign Area 37K/64K bytes, 1/1 segment ;;; Static-Area 523K/576K bytes, 9/9 segments ;;; Read-Write-Area 703K/704K bytes, 11/11 segments ;;; Readonly-Pointer-Area 1144K/1152K bytes, 18/18 segments ;;; Readonly-Non-Pointer-Area 3770K/3776K bytes, 59/59 segments NIL

See Also: gc-off

*gc-silence* Variable

Syntax:*gc-silence*

The variable*gc-silence* controls dynamic garbage collection messages.

This variable can have one of the following values:

If the value isnil, garbage collection messages are displayed on the standard output. This value is the default.

If the value ist, all garbage collection messages are suppressed.

If the value is a compiled function, that function is called with a single argument whenever a garbage collection message would normally appear. The argument can be bound to any of the following values:

  • :before

When the function is called immediately before a garbage collection is performed, the argument has the value:before.

  • :after

When the function is called immediately after a garbage collection is performed, the argument has the value:after.

  • :dynamic-expansion

When the function is called immediately after the dynamic areas are expanded, the argument has the value:dynamic-expansion.

  • :reserved-expansion

When the function is called immediately before the reserved free space is expanded, the argument has the value:reserved-expansion.

Because*gc-silence* procedures are called when normal memory allocation is impossible, an executing function that is bound to*gc-silence* should not use more than the amount of storage that is reserved by the value of the keyword:reserved-dynamic. This value defaults to 1024 bytes.

In addition, because*gc-silence* procedures are called when scheduling is inhibited, such procedures should not try to acquire process locks. It is an error for a process to acquire locks while scheduling is inhibited. You must write*gc-silence* procedures carefully because many activities use locking; for example, writing to a window uses locks. For more information about process locks, see Chapter 5, "The Multitasking Facility" in The Advanced User's Guide.

> (room)
;;; 1968 words [7872 bytes] of dynamic storage in use.
;;; 522256 words [2089024 bytes] of free storage available 
;;; before a GC. 1046480 words [4185920 bytes] of free 
;;; storage available if GC is disabled.
NIL

> (let ((*gc-silence* t)) (gc)) 5136 2091760 4188656

> (room) ;;; 1324 words [5296 bytes] of dynamic storage in use. ;;; 522900 words [2091600 bytes] of free storage available ;;; before a GC. 1047124 words [4188496 bytes] of free ;;; storage available if GC is disabled. NIL

gc-size Function

Syntax:gc-size

The functiongc-size returns the following multiple values:

The values returned by this function are the same as those returned by the functiongc.

> (gc-size)
5496
2091400
4188296

;;; Write a simple macro that uses GC-SIZE to determine how ;;; much dynamic storage is used by a function. This macro ;;; assumes that ephemeral garbage collection is off. > (defmacro how-much-consing-macro (&body body) '(let ((initial-gc-size (gc-size))) (unwind-protect (progn ,@body) ; multiple-value-prog1 (format t "~&~S words consed" ; that doesn't cons. (floor (- (gc-size) initial-gc-size) 4))))) ; 4 bytes per word. HOW-MUCH-CONSING-MACRO

> (defun how-much-consing (fn &rest args) (how-much-consing-macro (apply fn args))) HOW-MUCH-CONSING

> (compile 'how-much-consing) HOW-MUCH-CONSING

> (defun test (x y) (cons x y)) TEST

> (how-much-consing 'test 'a 'b) 100 words consed (A . B)

> (compile 'test) TEST

> (how-much-consing 'test 'a 'b) 2 words consed (A . B)

See Also: gc , room

room Function

Syntax:room &key :default &optional verbosity

The functionroom prints information about the current state of internal memory on the gc output stream. The gc output is defined by the value of the Common Lisp variable*gc-output*, which is a synonym stream that writes to*trace-output*.

If the optional verbosity argument is specified asnil, a terse summary is printed. If it is non-nil, a verbose description is given. If no argument is specified, or if the keyword argument:default is specified,room prints a moderate amount of information.

> (room nil)
;;; 775824 words [3103296 bytes] free
NIL

> (room) ;;; 792 words [3168 bytes] of dynamic storage in use. ;;; 523238 words [2092952 bytes] of free storage available before a GC. ;;; 1047268 words [4189072 bytes] of free storage available if GC is disabled. T

> (room :default) ;;; 792 words [3168 bytes] of dynamic storage in use. ;;; 523238 words [2092952 bytes] of free storage available before a GC. ;;; 1047268 words [4189072 bytes] of free storage available if GC is disabled. T

> (room t) ;;; 10350 words [41400 bytes] of dynamic storage in use. ;;; 775824 words [3103296 bytes] of free storage available ;;; before a GC. 1561998 words [6247992 bytes] of free ;;; storage available if GC is disabled. ;;; Semi-space Size: 3072K bytes [48 segments] ;;; Current Dynamic Area: Dynamic-1-Area ;;; GC Status: Enabled ;;; Reserved Free Space: 3200K bytes [50 segments] ;;; Memory Growth Limit: 32768K bytes [512 segments], total ;;; Memory Growth Rate: 256K bytes [4 segments] ;;; Reclamation Ratio: 33% desired free after garbage collection

;;; Area Information: ;;; Name Size [used/allocated] ;;; ---- ---- ;;; Ephemeral Level 0 1K/512K bytes, 1/8 segments ;;; Ephemeral Level 1 0K/640K bytes, 0/10 segments ;;; Ephemeral Level 2 0K/640K bytes, 0/10 segments ;;; Ephemeral Odd-level OSP 0K/512K bytes, 0/8 segments ;;; Ephemeral Even-level OSP 0K/640K bytes, 0/10 segments ;;; Dynamic-0-Area 0K/3072K bytes, 0/48 segments ;;; Dynamic-1-Area 41K/3071K bytes, 1/48 segments ;;; Discardable-Static-Area 513K/576K bytes, 9/9 segments ;;; Foreign Area 37K/64K bytes, 1/1 segment ;;; Static-Area 523K/576K bytes, 9/9 segments ;;; Read-Write-Area 703K/704K bytes, 11/11 segments ;;; Readonly-Pointer-Area 1144K/1152K bytes, 18/18 segments ;;; Readonly-Non-Pointer-Area 3771K/3776K bytes, 59/59 segments NIL

with-normal-consing-area Macro

Syntax:with-normal-consing-area {form}*

The macrowith-normal-consing-area causes objects to be created in ephemeral space when ephemeral garbage collection is turned on and in dynamic space when ephemeral garbage collection is off.

See Also: with-static-area

with-static-area Macro

Syntax:with-static-area {form}*

The macrowith-static-area evaluates a series of forms while forcing all consing to be done in the static area. Objects that are created are permanent and are never reclaimed by garbage collection.

The macrowith-static-area should be used with short series of forms to prevent the unintentional creation of objects in static space.

Note: Use this macro sparingly because available memory can quickly be exhausted.

;;; This example assumes you have a large defstruct called 
;;; large-object that creates large-object structures 
;;; that are retained indefinitely.  Creating 
;;; large-object structures in the static area will
;;; therefore speed garbage collection.  The following code 
;;; provides a wrapper to the defstruct constructor for 
;;; large-object so that large-object structures are 
;;; created in the static area:
> (defstruct (large-object (:constructor new-large-object))
    field-1
    field-2
    field-3
    field-4
    field-n)
LARGE-OBJECT

> (compile (defun make-large-object (&rest arguments) (with-static-area (apply #'new-large-object arguments)))) MAKE-LARGE-OBJECT

> (make-large-object :field-4 35) #S(LARGE-OBJECT FIELD-1 NIL FIELD-2 NIL FIELD-3 NIL FIELD-4 35 FIELD-N NIL)

;; Be cautious when using with-static-area. For example, the ;; following function could unintentionally cons in the static ;; area. If X is a bignum, the product and any intermediate ;; consing during the multiplication will occupy static space. ;; Furthermore, if the multiplication causes an error, the ;; error handler will cons in static space. > (compile (defun cons-in-static (x) (with-static-area (new-large-object :field-1 (* x x))))) CONS-IN-STATIC ;; The following function avoids extra consing in the static ;; space. > (compile (defun create-in-static (x) (let ((f1 (* x x))) (with-static-area (new-large-object :field-1 f1))))) CREATE-IN-STATIC

;; The following function shows another way to avoid extra ;; consing in static space. > (compile (defun create-in-static2 (x) (with-static-area (new-large-object :field-1 (with-normal-consing-area (* x x)))))) CREATE-IN-STATIC2

See Also: with-normal-consing-area


The User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker