Debian Codegraph @

src/doc/manual/extensions/memory_ref.txi

raw
1 @node Memory Management Reference
2 @subsection Memory Management Reference
3
4 @subsubheading Reference
5
6 @lspdef ext:stack-overflow
7 @deftp Condition ext:stack-overflow
8
9 Stack overflow condition
10
11 @paragraph Class Precedence List
12 @coderef{ext:stack-overflow}, @code{storage-condition}, @code{serious-condition}, @code{condition}, @code{t}
13
14 @paragraph Methods
15 @lspdef ext:stack-overflow-size
16 @defun ext:stack-overflow-size condition
17 @table @var
18 @item returns
19 A non-negative integer.
20 @end table
21 @end defun
22
23 @lspdef ext:stack-overflow-type
24 @defun ext:stack-overflow-type condition
25 @table @var
26 @item returns
27 A symbol from @ref{tab:mem-limits}, except @coderef{ext:heap-size}.
28 @end table
29 @end defun
30
31 @paragraph Description
32 This condition is signaled when one of the stack limits in @ref{tab:mem-limits} are violated or dangerously approached. It can be handled by resetting the limits and continuing, or jumping to an outer control point.
33
34 @end deftp
35
36
37 @lspdef ext:storage-exhausted
38 @deftp Condition ext:storage-exhausted
39
40 Memory overflow condition
41
42 @paragraph Class Precedence List
43 @coderef{ext:storage-exhausted}, @code{storage-condition}, @code{serious-condition}, @code{condition}, @code{t}
44
45 @paragraph Description
46 This condition is signaled when ECL exhausts the @coderef{ext:heap-size} limit from @ref{tab:mem-limits}. In handling this condition ECL follows this logic:
47 @itemize
48 @item
49 If the heap size limit was set to 0 (that is no limit), but there is some free space in the safety region ECL frees this space and issues a non-restartable error. The user may jump to an outer point or quit.
50 @item
51 If the heap size had a finite limit, ECL offers the user the chance to resize it, issuing a restartable condition. The user may at this point use @code{(ext:set-limit 'ext:heap-size 0)} to remove the heap limit and avoid further messages, or use the @code{(continue)} restart to let ECL enlarge the heap by some amount.
52 @item
53 Independently of the heap size limit, if ECL finds that there is no space to free or to grow, ECL simply quits. There will be no chance to do some cleanup because there is no way to allocate any additional data.
54 @end itemize
55 @end deftp
56
57
58 @lspdef ext:get-finalizer
59 @defun ext:get-finalizer object
60 @table @var
61 @item object
62 Any lisp object.
63 @end table
64
65 @paragraph Description
66 This function returns the finalizer associated to an object, or @code{nil}.
67 @end defun
68
69
70 @lspdef ext:get-limit
71 @defun ext:get-limit concept
72 @table @var
73 @item concept
74 A symbol.
75 @end table
76
77 @paragraph Description
78 Queries the different memory and stack limits that condition ECL's behavior. The value to be queried is denoted by the symbol @var{concept}, which should be one from the list: @ref{tab:mem-limits}
79 @end defun
80
81 @lspdef ext:set-finalizer
82 @defun ext:set-finalizer object function
83 Associate a finalizer to an object.
84 @table @var
85 @item object
86 Any lisp object.
87 @item function
88 A function or closure that takes one argument or @code{nil}.
89 @end table
90
91 @paragraph Description
92 If @var{function} is @code{nil}, no finalizer is associated to the object. Otherwise @var{function} must be a function or a closure of one argument, which will be invoked before the object is destroyed.
93
94 @paragraph Example
95 Close a file associated to an object.
96
97 @lisp
98 (defclass my-class () ((file :initarg :file :initform nil)))
99
100 (defun finalize-my-class (x)
101 (let ((s (slot-value x 'file)))
102 (when s (format t "~%;;; Closing" s) (close s))))
103
104 (defmethod initialize-instance :around ((my-instance my-class) &rest args)
105 (ext:set-finalizer my-instance #'finalize-my-class)
106 (call-next-method))
107
108 (progn
109 (make-instance 'my-class :file (open "~/.ecl.old" :direction :input))
110 nil)
111
112 (si::gc t)
113 (si::gc t)
114
115 ;; Closing
116 @end lisp
117 @end defun
118
119
120 @lspdef ext:set-limit
121 @defun ext:set-limit concept value
122 Set a memory or stack limit.
123 @table @var
124 @item concept
125 A symbol.
126 @item value
127 A positive integer.
128 @end table
129 Changes the different memory and stack limits that condition ECL's behavior. The value to be changed is denoted by the symbol @var{concept}, while the @var{value} is the new maximum size. The valid symbols and units are listed in @ref{tab:mem-limits}.
130
131 Note that the limit has to be positive, but it may be smaller than the previous value of the limit. However, if the supplied value is smaller than what ECL is using at the moment, the new value will be silently ignored.
132
133 @float Table, tab:mem-limits
134 @caption{Customizable memory limits}
135 @multitable @columnfractions .25 .25 .25 .25
136 @headitem Concept @tab Units @tab Default @tab Command line
137 @item ext:frame-stack @tab Nested frames @tab 2048 @tab @code{--frame-stack}
138 @item ext:binding-stack @tab Bindings @tab 8192 @tab
139 @item ext:c-stack @tab Bytes @tab 128 kilobytes @tab @code{--c-stack}
140 @item ext:heap-size @tab Bytes @tab 256 megabytes @tab @code{--heap-size}
141 @item ext:lisp-stack @tab Bytes @tab 32 kilobyes @tab @code{--lisp-stack}
142 @end multitable
143 @end float
144
145 @end defun