summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorYuuki Harano <masm+github@masm11.me>2020-12-05 20:30:42 +0900
committerYuuki Harano <masm+github@masm11.me>2020-12-05 20:30:42 +0900
commitda92d5700eff8f628b6306202635a2514eb8b387 (patch)
treee632bd68bf0286525e59ce35326986c1cb6f7755 /src/alloc.c
parentd46a223d8595e8edb67c6361033625797503cacf (diff)
parentdc39c66d3bb6b1db6af0519659ff154bf6d8a5d1 (diff)
downloademacs-da92d5700eff8f628b6306202635a2514eb8b387.tar.gz
emacs-da92d5700eff8f628b6306202635a2514eb8b387.tar.bz2
emacs-da92d5700eff8f628b6306202635a2514eb8b387.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 1a707cfa57e..51088eb0e77 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6157,10 +6157,17 @@ where each entry has the form (NAME SIZE USED FREE), where:
- FREE is the number of those objects that are not live but that Emacs
keeps around for future allocations (maybe because it does not know how
to return them to the OS).
+
However, if there was overflow in pure space, and Emacs was dumped
using the 'unexec' method, `garbage-collect' returns nil, because
real GC can't be done.
-See Info node `(elisp)Garbage Collection'. */)
+
+Note that calling this function does not guarantee that absolutely all
+unreachable objects will be garbage-collected. Emacs uses a
+mark-and-sweep garbage collector, but is conservative when it comes to
+collecting objects in some circumstances.
+
+For further details, see Info node `(elisp)Garbage Collection'. */)
(void)
{
if (garbage_collection_inhibited)
@@ -6205,6 +6212,30 @@ See Info node `(elisp)Garbage Collection'. */)
return CALLMANY (Flist, total);
}
+DEFUN ("garbage-collect-maybe", Fgarbage_collect_maybe,
+Sgarbage_collect_maybe, 1, 1, "",
+ doc: /* Call `garbage-collect' if enough allocation happened.
+FACTOR determines what "enough" means here:
+If FACTOR is a positive number N, it means to run GC if more than
+1/Nth of the allocations needed to trigger automatic allocation took
+place.
+Therefore, as N gets higher, this is more likely to perform a GC.
+Returns non-nil if GC happened, and nil otherwise. */)
+ (Lisp_Object factor)
+{
+ CHECK_FIXNAT (factor);
+ EMACS_INT fact = XFIXNAT (factor);
+
+ EMACS_INT since_gc = gc_threshold - consing_until_gc;
+ if (fact >= 1 && since_gc > gc_threshold / fact)
+ {
+ garbage_collect ();
+ return Qt;
+ }
+ else
+ return Qnil;
+}
+
/* Mark Lisp objects in glyph matrix MATRIX. Currently the
only interesting objects referenced from glyphs are strings. */
@@ -7549,6 +7580,7 @@ N should be nonnegative. */);
defsubr (&Smake_finalizer);
defsubr (&Spurecopy);
defsubr (&Sgarbage_collect);
+ defsubr (&Sgarbage_collect_maybe);
defsubr (&Smemory_info);
defsubr (&Smemory_use_counts);
#ifdef GNU_LINUX