summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-05-01 11:51:35 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-05-01 11:51:43 +0200
commit29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035 (patch)
tree65df665be56947d52a993896705a6c7c03503019 /src/alloc.c
parent6984f325bdbaf15b1190d0d03b01eebe9cfbbb71 (diff)
downloademacs-29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035.tar.gz
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. */)
}
#endif
+#ifdef HAVE_MALLOC_TRIM
+DEFUN ("malloc-trim", Fmalloc_trim, Smalloc_trim, 0, 1, "",
+ doc: /* Release free memory from the heap.
+This function asks libc to return unused memory back to the operating
+system. This function isn't guaranteed to do anything, and is mainly
+meant as a debugging tool.
+
+If LEAVE_PADDING is given, ask the system to leave that much unused
+spaced in the heap. This should be an integer, and if not given,
+defaults to 0.
+
+This function returns nil if no memory could be returned to the
+system, and non-nil if some memory could be returned. */)
+ (Lisp_Object leave_padding)
+{
+ int pad = 0;
+
+ if (! NILP (leave_padding))
+ {
+ CHECK_FIXNAT (leave_padding);
+ pad = XFIXNUM (leave_padding);
+ }
+
+ /* 1 means that memory was released to the system. */
+ if (malloc_trim (pad) == 1)
+ return Qt;
+ else
+ return Qnil;
+}
+#endif
+
static bool
symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj)
{
@@ -7830,6 +7861,9 @@ N should be nonnegative. */);
defsubr (&Smalloc_info);
#endif
+#ifdef HAVE_MALLOC_TRIM
+ defsubr (&Smalloc_trim);
+#endif
defsubr (&Ssuspicious_object);
Lisp_Object watcher;