aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-05-01 11:51:35 +0200
committerLars Ingebrigtsen2022-05-01 11:51:43 +0200
commit29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035 (patch)
tree65df665be56947d52a993896705a6c7c03503019 /src/alloc.c
parent6984f325bdbaf15b1190d0d03b01eebe9cfbbb71 (diff)
downloademacs-29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035.tar.gz
emacs-29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035.zip
Add new function `malloc-trim'
* configure.ac (PGTK_LIBS): Check for malloc_trim. * src/alloc.c (Fmalloc_trim): Add new function (bug#45200).
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index b9712859c38..661f37dd5cc 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -7479,6 +7479,37 @@ arenas. */)
7479} 7479}
7480#endif 7480#endif
7481 7481
7482#ifdef HAVE_MALLOC_TRIM
7483DEFUN ("malloc-trim", Fmalloc_trim, Smalloc_trim, 0, 1, "",
7484 doc: /* Release free memory from the heap.
7485This function asks libc to return unused memory back to the operating
7486system. This function isn't guaranteed to do anything, and is mainly
7487meant as a debugging tool.
7488
7489If LEAVE_PADDING is given, ask the system to leave that much unused
7490spaced in the heap. This should be an integer, and if not given,
7491defaults to 0.
7492
7493This function returns nil if no memory could be returned to the
7494system, and non-nil if some memory could be returned. */)
7495 (Lisp_Object leave_padding)
7496{
7497 int pad = 0;
7498
7499 if (! NILP (leave_padding))
7500 {
7501 CHECK_FIXNAT (leave_padding);
7502 pad = XFIXNUM (leave_padding);
7503 }
7504
7505 /* 1 means that memory was released to the system. */
7506 if (malloc_trim (pad) == 1)
7507 return Qt;
7508 else
7509 return Qnil;
7510}
7511#endif
7512
7482static bool 7513static bool
7483symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj) 7514symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj)
7484{ 7515{
@@ -7830,6 +7861,9 @@ N should be nonnegative. */);
7830 7861
7831 defsubr (&Smalloc_info); 7862 defsubr (&Smalloc_info);
7832#endif 7863#endif
7864#ifdef HAVE_MALLOC_TRIM
7865 defsubr (&Smalloc_trim);
7866#endif
7833 defsubr (&Ssuspicious_object); 7867 defsubr (&Ssuspicious_object);
7834 7868
7835 Lisp_Object watcher; 7869 Lisp_Object watcher;