emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master ec1b4d9: Rewrite memory-limit in Lisp


From: Paul Eggert
Subject: [Emacs-diffs] master ec1b4d9: Rewrite memory-limit in Lisp
Date: Sat, 16 Jun 2018 11:33:45 -0400 (EDT)

branch: master
commit ec1b4d9a51db61b77c3953f3de4339f34e512c42
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Rewrite memory-limit in Lisp
    
    Have it return Emacs virtual memory size, not the sbrk value
    which is often useless newadays.
    * doc/lispref/internals.texi (Garbage Collection):
    * etc/NEWS: Document this.
    * lisp/subr.el (memory-limit): New implementation in Lisp,
    written in terms of process-attributes, and which returns
    virtual memory size.
    * src/alloc.c (Fmemory_limit): Remove C implementation.
---
 doc/lispref/internals.texi |  6 ++----
 etc/NEWS                   |  3 +++
 lisp/subr.el               |  4 ++++
 src/alloc.c                | 19 -------------------
 4 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index 9cf1a4f..faaf26f 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -507,10 +507,8 @@ function @code{memory-limit} provides information on the 
total amount of
 memory Emacs is currently using.
 
 @defun memory-limit
-This function returns the address of the last byte Emacs has allocated,
-divided by 1024.  We divide the value by 1024 to make sure it fits in a
-Lisp integer.
-
+This function returns an estimate of the total amount of bytes of
+virtual memory that Emacs is currently using, divided by 1024.
 You can use this to get a general idea of how your actions affect the
 memory usage.
 @end defun
diff --git a/etc/NEWS b/etc/NEWS
index cecd3f8..d59b4a7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -665,6 +665,9 @@ instead of just Microsoft platforms.  This fixes a 
'get-free-disk-space'
 bug on OS X 10.8 and later (Bug#28639).
 
 +++
+** 'memory-limit' now returns a better estimate of memory consumption.
+
++++
 ** New macro 'combine-change-calls' arranges to call the change hooks
 ('before-change-functions' and 'after-change-functions') just once
 each around a sequence of lisp forms, given a region.  This is
diff --git a/lisp/subr.el b/lisp/subr.el
index 4a2b797..8123e60 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2182,6 +2182,10 @@ It can be retrieved with `(process-get PROCESS 
PROPNAME)'."
   (set-process-plist process
                     (plist-put (process-plist process) propname value)))
 
+(defun memory-limit ()
+  "Return an estimate of Emacs virtual memory usage, divided by 1024."
+  (or (cdr (assq 'vsize (process-attributes (emacs-pid)))) 0))
+
 
 ;;;; Input and display facilities.
 
diff --git a/src/alloc.c b/src/alloc.c
index 2863586..cc846fd 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -7120,24 +7120,6 @@ or memory information can't be obtained, return nil.  */)
 
 /* Debugging aids.  */
 
-DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0,
-       doc: /* Return the address of the last byte Emacs has allocated, 
divided by 1024.
-This may be helpful in debugging Emacs's memory usage.
-We divide the value by 1024 to make sure it fits in a Lisp integer.  */)
-  (void)
-{
-  Lisp_Object end;
-
-#if defined HAVE_NS || defined __APPLE__ || !HAVE_SBRK
-  /* Avoid warning.  sbrk has no relation to memory allocated anyway.  */
-  XSETINT (end, 0);
-#else
-  XSETINT (end, (intptr_t) (char *) sbrk (0) / 1024);
-#endif
-
-  return end;
-}
-
 DEFUN ("memory-use-counts", Fmemory_use_counts, Smemory_use_counts, 0, 0, 0,
        doc: /* Return a list of counters that measure how much consing there 
has been.
 Each of these counters increments for a certain kind of object.
@@ -7495,7 +7477,6 @@ The time is in seconds as a floating point value.  */);
   defsubr (&Smake_finalizer);
   defsubr (&Spurecopy);
   defsubr (&Sgarbage_collect);
-  defsubr (&Smemory_limit);
   defsubr (&Smemory_info);
   defsubr (&Smemory_use_counts);
   defsubr (&Ssuspicious_object);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]