]> git.eshelyaron.com Git - emacs.git/commitdiff
* internals.texi (Stack-allocated Objects): Describe this feature.
authorDmitry Antipov <dmantipov@yandex.ru>
Tue, 30 Sep 2014 15:35:16 +0000 (19:35 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Tue, 30 Sep 2014 15:35:16 +0000 (19:35 +0400)
doc/lispref/ChangeLog
doc/lispref/internals.texi

index 1a85b126ffe3d24e9504830f66566ff9256a88d4..36918dac2e4c0461246b58386df4b2c5eb5f2eea 100644 (file)
@@ -1,3 +1,7 @@
+2014-09-30  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       * internals.texi (Stack-allocated Objects): Describe this feature.
+
 2014-09-15  Daniel Colascione  <dancol@dancol.org>
 
        * text.texi (Registers): Make `insert-register' documentation
index 3d85b474d4b749b369b6a8c0a532305642f8a132..1bafd22fd43a584f7ea5b5a3a4e129c9831cd5a2 100644 (file)
@@ -14,6 +14,7 @@ internal aspects of GNU Emacs that may be of interest to C programmers.
 * Building Emacs::      How the dumped Emacs is made.
 * Pure Storage::        Kludge to make preloaded Lisp functions shareable.
 * Garbage Collection::  Reclaiming space for Lisp objects no longer used.
+* Stack-allocated Objects::    Temporary conses and strings on C stack.
 * Memory Usage::        Info about total size of Lisp objects made so far.
 * C Dialect::           What C variant Emacs is written in.
 * Writing Emacs Primitives::   Writing C code for Emacs.
@@ -529,6 +530,31 @@ during garbage collection so far in this Emacs session, as a
 floating-point number.
 @end defvar
 
+@node Stack-allocated Objects
+@section Stack-allocated Objects
+
+@cindex stack allocation overview
+  The garbage collector described above is used to manage data visible
+from Lisp program, as well as the most of data internally used by the
+interpreter.  But sometimes it may be useful to allocate temporary
+internal (i.e. not visible for Lisp program) objects using C stack of
+an interpreter.  Currently conses and strings are the only objects which
+can be allocated in that way.  Strings are limited to ASCII characters
+only and should be treated as immutable (calling @code{ASET} on them is
+undefined).
+
+@cindex stack allocation internals
+  In C, this is implemented as a special macros which expands to
+a @code{Lisp_Object} with block-scoped semantics and lifetime (see
+the code around @code{USE_STACK_LISP_OBJECTS} in @file{lisp.h}).  This
+means that these objects are not managed by the garbage collector;
+instead, they are allocated like local variables in C and automatically
+freed when an execution reaches an end of the corresponding scope.  Thus,
+allocation and freeing are faster than using garbage collector.  But
+remember that passing them out of their scope results in undefined
+behavior.  Think twice before using this feature and carefully debug
+your code with @code{GC_CHECK_MARKED_OBJECTS} (see @file{alloc.c}).
+
 @node Memory Usage
 @section Memory Usage
 @cindex memory usage