diff options
| author | Lars Ingebrigtsen | 2022-05-01 11:51:35 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-01 11:51:43 +0200 |
| commit | 29f3d4d2c69a0e9d2ab0a13ee6952fa9cf4d6035 (patch) | |
| tree | 65df665be56947d52a993896705a6c7c03503019 /src/alloc.c | |
| parent | 6984f325bdbaf15b1190d0d03b01eebe9cfbbb71 (diff) | |
| download | emacs-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.c | 34 |
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 | ||
| 7483 | DEFUN ("malloc-trim", Fmalloc_trim, Smalloc_trim, 0, 1, "", | ||
| 7484 | doc: /* Release free memory from the heap. | ||
| 7485 | This function asks libc to return unused memory back to the operating | ||
| 7486 | system. This function isn't guaranteed to do anything, and is mainly | ||
| 7487 | meant as a debugging tool. | ||
| 7488 | |||
| 7489 | If LEAVE_PADDING is given, ask the system to leave that much unused | ||
| 7490 | spaced in the heap. This should be an integer, and if not given, | ||
| 7491 | defaults to 0. | ||
| 7492 | |||
| 7493 | This function returns nil if no memory could be returned to the | ||
| 7494 | system, 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 | |||
| 7482 | static bool | 7513 | static bool |
| 7483 | symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj) | 7514 | symbol_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; |