| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE book [ |
| 3 |
<!ENTITY % eclent SYSTEM "ecl.ent"> |
| 4 |
%eclent; |
| 5 |
]> |
| 6 |
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> |
| 7 |
<chapter> |
| 8 |
<title>Memory Management</title> |
| 9 |
<section xml:id="ext.memory.dict"> |
| 10 |
<title>Memory Management Reference</title> |
| 11 |
|
| 12 |
<!-- ====================================================================== --> |
| 13 |
<!-- EXT:STACK-OVERFLOW --> |
| 14 |
<!-- ====================================================================== --> |
| 15 |
|
| 16 |
<refentry xml:id="ref.memory.stack-overflow"> |
| 17 |
<refnamediv> |
| 18 |
<refname><classname>ext:stack-overflow</classname></refname> |
| 19 |
<refpurpose>Stack overflow condition.</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
|
| 22 |
<refsynopsisdiv> |
| 23 |
<title>Class Precedence List</title> |
| 24 |
<para> |
| 25 |
<classname>ext:stack-overflow</classname>, |
| 26 |
<classname>storage-condition</classname>, |
| 27 |
<classname>serious-condition</classname>, |
| 28 |
<classname>condition</classname>, |
| 29 |
<classname>t</classname> |
| 30 |
</para> |
| 31 |
</refsynopsisdiv> |
| 32 |
|
| 33 |
<refsynopsisdiv> |
| 34 |
<title>Methods</title> |
| 35 |
<funcsynopsis> |
| 36 |
<funcprototype> |
| 37 |
<funcdef>ext:stack-overflow-size</funcdef> |
| 38 |
<paramdef><parameter>condition</parameter></paramdef> |
| 39 |
<modifier><replaceable>integer</replaceable></modifier> |
| 40 |
</funcprototype> |
| 41 |
<funcprototype> |
| 42 |
<funcdef>ext:stack-overflow-type</funcdef> |
| 43 |
<paramdef><parameter>condition</parameter></paramdef> |
| 44 |
<modifier><replaceable>concept</replaceable></modifier> |
| 45 |
</funcprototype> |
| 46 |
</funcsynopsis> |
| 47 |
<variablelist> |
| 48 |
<varlistentry> |
| 49 |
<term><replaceable>integer</replaceable></term> |
| 50 |
<listitem><para>A non-negative integer.</para></listitem> |
| 51 |
</varlistentry> |
| 52 |
<varlistentry> |
| 53 |
<term><replaceable>concept</replaceable></term> |
| 54 |
<listitem><para>A symbol from <xref |
| 55 |
linkend="table.memory.limits"/>, except |
| 56 |
<varname>ext:heap-size</varname>.</para></listitem> |
| 57 |
</varlistentry> |
| 58 |
</variablelist> |
| 59 |
</refsynopsisdiv> |
| 60 |
|
| 61 |
<refsect1> |
| 62 |
<title>Description</title> |
| 63 |
<para>This condition is signaled when one of the stack limits in |
| 64 |
<xref linkend="table.memory.limits"/> are violated or dangerously |
| 65 |
approached. It can be handled by resetting the limits and |
| 66 |
continuing, or jumping to an outer control point.</para> |
| 67 |
</refsect1> |
| 68 |
|
| 69 |
</refentry> |
| 70 |
|
| 71 |
<!-- ====================================================================== --> |
| 72 |
<!-- EXT:STORAGE-EXHAUSTED --> |
| 73 |
<!-- ====================================================================== --> |
| 74 |
|
| 75 |
<refentry xml:id="ref.memory.storage-exhausted"> |
| 76 |
<refnamediv> |
| 77 |
<refname><classname>ext:storage-exhausted</classname></refname> |
| 78 |
<refpurpose>Memory overflow condition.</refpurpose> |
| 79 |
</refnamediv> |
| 80 |
|
| 81 |
<refsynopsisdiv> |
| 82 |
<title>Class Precedence List</title> |
| 83 |
<para> |
| 84 |
<classname>ext:storage-exhausted</classname>, |
| 85 |
<classname>storage-condition</classname>, |
| 86 |
<classname>serious-condition</classname>, |
| 87 |
<classname>condition</classname>, |
| 88 |
<classname>t</classname> |
| 89 |
</para> |
| 90 |
</refsynopsisdiv> |
| 91 |
|
| 92 |
|
| 93 |
<refsect1> |
| 94 |
<title>Description</title> |
| 95 |
<para>This condition is signaled when &ECL; exhausts the |
| 96 |
<varname>ext:heap-size</varname> limit from <xref |
| 97 |
linkend="table.memory.limits"/>. In handling this condition &ECL; follows |
| 98 |
this logic</para> |
| 99 |
<itemizedlist> |
| 100 |
<listitem><para>If the heap size limit was set to 0 (that is no limit), but |
| 101 |
there is some free space in the safety region &ECL; frees this space and |
| 102 |
issues a non-restartable error. The user may jump to an outer point or |
| 103 |
quit.</para></listitem> |
| 104 |
|
| 105 |
<listitem><para>If the heap size had a finite limit, &ECL; offers the user |
| 106 |
the chance to resize it, issuing a restartable condition. The user may at |
| 107 |
this point use <code>(ext:set-limit 'ext:heap-size 0)</code> to remove the |
| 108 |
heap limit and avoid further messages, or use the <code>(continue)</code> |
| 109 |
restart to let &ECL; enlarge the heap by some amount.</para></listitem> |
| 110 |
|
| 111 |
<listitem><para>Independently of the heap size limit, if &ECL; finds that |
| 112 |
ther is no space to free or to grow, &ECL; simply quits. There will be no |
| 113 |
chance to do some cleanup because there is no way to cons any additional |
| 114 |
data.</para></listitem> |
| 115 |
</itemizedlist> |
| 116 |
</refsect1> |
| 117 |
|
| 118 |
</refentry> |
| 119 |
|
| 120 |
<!-- ====================================================================== --> |
| 121 |
<!-- EXT:GET-FINALIZER --> |
| 122 |
<!-- ====================================================================== --> |
| 123 |
|
| 124 |
<refentry xml:id="ref.memory.get-finalizer"> |
| 125 |
<refnamediv> |
| 126 |
<refname><function>ext:get-finalizer</function></refname> |
| 127 |
<refpurpose>Return finalizer associated to an object.</refpurpose> |
| 128 |
</refnamediv> |
| 129 |
|
| 130 |
<refsynopsisdiv> |
| 131 |
<title>Function</title> |
| 132 |
<funcsynopsis> |
| 133 |
<funcprototype> |
| 134 |
<funcdef>ext:get-finalizer</funcdef> |
| 135 |
<paramdef><parameter>object</parameter></paramdef> |
| 136 |
</funcprototype> |
| 137 |
</funcsynopsis> |
| 138 |
<variablelist> |
| 139 |
<varlistentry> |
| 140 |
<term><replaceable>object</replaceable></term> |
| 141 |
<listitem><para>Any lisp object.</para></listitem> |
| 142 |
</varlistentry> |
| 143 |
</variablelist> |
| 144 |
</refsynopsisdiv> |
| 145 |
|
| 146 |
<refsect1> |
| 147 |
<title>Description</title> |
| 148 |
<para>This function returns the finalizer associated to an object, or &nil;.</para> |
| 149 |
</refsect1> |
| 150 |
|
| 151 |
</refentry> |
| 152 |
|
| 153 |
<!-- ====================================================================== --> |
| 154 |
<!-- EXT::GET-LIMIT --> |
| 155 |
<!-- ====================================================================== --> |
| 156 |
|
| 157 |
<refentry xml:id="ref.memory.get-limit"> |
| 158 |
<refnamediv> |
| 159 |
<refname><function>ext:get-limit</function></refname> |
| 160 |
<refpurpose>Query a memory or stack limit.</refpurpose> |
| 161 |
</refnamediv> |
| 162 |
|
| 163 |
<refsynopsisdiv> |
| 164 |
<title>Function</title> |
| 165 |
<funcsynopsis> |
| 166 |
<funcprototype> |
| 167 |
<funcdef>ext:get-limit</funcdef> |
| 168 |
<paramdef><parameter>concept</parameter></paramdef> |
| 169 |
</funcprototype> |
| 170 |
</funcsynopsis> |
| 171 |
<variablelist> |
| 172 |
<varlistentry> |
| 173 |
<term><replaceable>concept</replaceable></term> |
| 174 |
<listitem><para>A symbol.</para></listitem> |
| 175 |
</varlistentry> |
| 176 |
</variablelist> |
| 177 |
</refsynopsisdiv> |
| 178 |
|
| 179 |
<refsect1> |
| 180 |
<title>Description</title> |
| 181 |
|
| 182 |
<para>Queries the different memory and stack limits that condition |
| 183 |
&ECL;'s behavior. The value to be queried is denoted by the symbol |
| 184 |
<replaceable>concept</replaceable>, which should be one from the |
| 185 |
list <xref linkend="table.memory.limits"/></para> |
| 186 |
|
| 187 |
</refsect1> |
| 188 |
|
| 189 |
</refentry> |
| 190 |
|
| 191 |
<!-- ====================================================================== --> |
| 192 |
<!-- EXT::SET-FINALIZER --> |
| 193 |
<!-- ====================================================================== --> |
| 194 |
|
| 195 |
<refentry xml:id="ref.memory.set-finalizer"> |
| 196 |
<refnamediv> |
| 197 |
<refname><function>ext:set-finalizer</function></refname> |
| 198 |
<refpurpose>Associate a finalizer to an object.</refpurpose> |
| 199 |
</refnamediv> |
| 200 |
|
| 201 |
<refsynopsisdiv> |
| 202 |
<title>Function</title> |
| 203 |
<funcsynopsis> |
| 204 |
<funcprototype> |
| 205 |
<funcdef>ext:set-finalizer</funcdef> |
| 206 |
<paramdef><parameter>object</parameter></paramdef> |
| 207 |
<paramdef><parameter>function</parameter></paramdef> |
| 208 |
</funcprototype> |
| 209 |
</funcsynopsis> |
| 210 |
<variablelist> |
| 211 |
<varlistentry> |
| 212 |
<term><replaceable>object</replaceable></term> |
| 213 |
<listitem><para>Any lisp object.</para></listitem> |
| 214 |
</varlistentry> |
| 215 |
<varlistentry> |
| 216 |
<term><replaceable>function</replaceable></term> |
| 217 |
<listitem><para>A function or closure that takes one argument or &nil;.</para></listitem> |
| 218 |
</varlistentry> |
| 219 |
</variablelist> |
| 220 |
</refsynopsisdiv> |
| 221 |
|
| 222 |
<refsect1> |
| 223 |
<title>Description</title> |
| 224 |
|
| 225 |
<para>If <replaceable>function</replaceable> is &nil; no finalizer is |
| 226 |
associated to the object. Otherwise <replaceable>function</replaceable> must |
| 227 |
be a function or a closure of one argument, which will be invoked before the |
| 228 |
object is destroyed.</para> |
| 229 |
</refsect1> |
| 230 |
|
| 231 |
<refsect1> |
| 232 |
<title>Example</title> |
| 233 |
<para>Close a file associated to an object.</para> |
| 234 |
<programlisting> |
| 235 |
(defclass my-class () ((file :initarg :file :initform nil))) |
| 236 |
|
| 237 |
(defun finalize-my-class (x) |
| 238 |
(let ((s (slot-value x 'file))) |
| 239 |
(when s (format t "~%;;; Closing" s) (close s)))) |
| 240 |
|
| 241 |
(defmethod initialize-instance :around ((my-instance my-class) &rest args) |
| 242 |
(ext:set-finalizer my-instance #'finalize-my-class) |
| 243 |
(call-next-method)) |
| 244 |
|
| 245 |
(progn |
| 246 |
(make-instance 'my-class :file (open "~/.ecl.old" :direction :input)) |
| 247 |
nil) |
| 248 |
|
| 249 |
(si::gc t) |
| 250 |
(si::gc t) |
| 251 |
|
| 252 |
;; Closing |
| 253 |
</programlisting> |
| 254 |
</refsect1> |
| 255 |
|
| 256 |
</refentry> |
| 257 |
|
| 258 |
<!-- ====================================================================== --> |
| 259 |
<!-- EXT::SET-LIMIT --> |
| 260 |
<!-- ====================================================================== --> |
| 261 |
|
| 262 |
<refentry xml:id="ref.memory.set-limit"> |
| 263 |
<refnamediv> |
| 264 |
<refname><function>ext:set-limit</function></refname> |
| 265 |
<refpurpose>Set a memory or stack limit.</refpurpose> |
| 266 |
</refnamediv> |
| 267 |
|
| 268 |
<refsynopsisdiv> |
| 269 |
<title>Function</title> |
| 270 |
<funcsynopsis> |
| 271 |
<funcprototype> |
| 272 |
<funcdef>ext:set-limit</funcdef> |
| 273 |
<paramdef><parameter>concept</parameter></paramdef> |
| 274 |
<paramdef><parameter>value</parameter></paramdef> |
| 275 |
</funcprototype> |
| 276 |
</funcsynopsis> |
| 277 |
<variablelist> |
| 278 |
<varlistentry> |
| 279 |
<term><replaceable>concept</replaceable></term> |
| 280 |
<listitem><para>A symbol.</para></listitem> |
| 281 |
</varlistentry> |
| 282 |
<varlistentry> |
| 283 |
<term><replaceable>function</replaceable></term> |
| 284 |
<listitem><para>A positive integer.</para></listitem> |
| 285 |
</varlistentry> |
| 286 |
</variablelist> |
| 287 |
</refsynopsisdiv> |
| 288 |
|
| 289 |
<refsect1> |
| 290 |
<title>Description</title> |
| 291 |
|
| 292 |
<para>Changes the different memory and stack limits that condition |
| 293 |
&ECL;'s behavior. The value to be changed is denoted by the symbol |
| 294 |
<replaceable>concept</replaceable>, while the |
| 295 |
<replaceable>value</replaceable> is the new maximum size. The valid |
| 296 |
symbols and units are listed in <xref |
| 297 |
linkend="table.memory.limits"/>.</para> |
| 298 |
|
| 299 |
<para>Note that the limit has to be positive, but it may be smaller |
| 300 |
than the previous value of the limit. However, if the supplied value |
| 301 |
is smaller than what &ECL; is using at the moment, the new value |
| 302 |
will be silently ignored.</para> |
| 303 |
|
| 304 |
<table xml:id="table.memory.limits"> |
| 305 |
<title>Customizable memory limits</title> |
| 306 |
<tgroup cols="3"> |
| 307 |
<thead> |
| 308 |
<row> |
| 309 |
<entry>Concept</entry> |
| 310 |
<entry>Units</entry> |
| 311 |
<entry>Default</entry> |
| 312 |
<entry>Command line</entry> |
| 313 |
</row> |
| 314 |
</thead> |
| 315 |
<tbody> |
| 316 |
<row> |
| 317 |
<entry><varname>ext:frame-stack</varname></entry> |
| 318 |
<entry>Nested frames</entry> |
| 319 |
<entry>2048</entry> |
| 320 |
<entry>--frame-stack</entry> |
| 321 |
</row> |
| 322 |
<row> |
| 323 |
<entry><varname>ext:binding-stack</varname></entry> |
| 324 |
<entry>Bindings</entry> |
| 325 |
<entry>8192</entry> |
| 326 |
<entry></entry> |
| 327 |
</row> |
| 328 |
<row> |
| 329 |
<entry><varname>ext:c-stack</varname></entry> |
| 330 |
<entry>Bytes</entry> |
| 331 |
<entry>128 kilobytes</entry> |
| 332 |
<entry>--c-stack</entry> |
| 333 |
</row> |
| 334 |
<row> |
| 335 |
<entry><varname>ext:heap-size</varname></entry> |
| 336 |
<entry>Bytes</entry> |
| 337 |
<entry>256 megabytes</entry> |
| 338 |
<entry>--heap-size</entry> |
| 339 |
</row> |
| 340 |
<row> |
| 341 |
<entry><varname>ext:lisp-stack</varname></entry> |
| 342 |
<entry>Bytes</entry> |
| 343 |
<entry>32 kilobytes</entry> |
| 344 |
<entry>--lisp-stack</entry> |
| 345 |
</row> |
| 346 |
</tbody> |
| 347 |
</tgroup> |
| 348 |
</table> |
| 349 |
|
| 350 |
</refsect1> |
| 351 |
|
| 352 |
</refentry> |
| 353 |
</section> |
| 354 |
</chapter> |
| 355 |
</book> |
| 356 |
<!-- Keep this comment at the end of the file |
| 357 |
Local variables: |
| 358 |
mode: nxml |
| 359 |
sgml-parent-document: "ecl.xml" |
| 360 |
sgml-indent-step: 1 |
| 361 |
nxml-child-indent: 1 |
| 362 |
nxml-outline-child-indent: 1 |
| 363 |
fill-column: 79 |
| 364 |
End: |
| 365 |
--> |