=== modified file 'src/alloc.c' --- src/alloc.c 2011-12-12 05:32:49 +0000 +++ src/alloc.c 2011-12-19 06:06:04 +0000 @@ -75,6 +75,10 @@ #define MMAP_MAX_AREAS 100000000 +/* Value of mallinfo ().fordblks as seen at the end of last GC. */ + +static int bytes_free; + #else /* not DOUG_LEA_MALLOC */ /* The following come from gmalloc.c. */ @@ -5271,6 +5275,10 @@ total[7] = Fcons (make_number (total_strings), make_number (total_free_strings)); +#ifdef DOUG_LEA_MALLOC + bytes_free = mallinfo ().fordblks; +#endif + #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES { /* Compute average percentage of zombies. */ @@ -6221,6 +6229,33 @@ return end; } +DEFUN ("memory-free", Fmemory_free, Smemory_free, 0, 0, 0, + doc: /* Return a list of two counters that measure how much free +memory is hold by the Emacs process. Both counters are +in KBytes. First counter shows how much memory holds in +a free lists maintained by the Emacs itself. Second counter +shows how much free memory is in the heap. If the second +counter is zero, heap statistics is not available. */) + (void) +{ + Lisp_Object data[2]; + + data[0] = make_number + (min (MOST_POSITIVE_FIXNUM, + (total_free_conses * sizeof (struct Lisp_Cons) + + total_free_markers * sizeof (union Lisp_Misc) + + total_free_symbols * sizeof (struct Lisp_Symbol) + + total_free_floats * sizeof (struct Lisp_Float) + + total_free_intervals * sizeof (struct interval) + + total_free_strings * sizeof (struct Lisp_String)) / 1024)); +#ifdef DOUG_LEA_MALLOC + data[1] = make_number (min (MOST_POSITIVE_FIXNUM, bytes_free / 1024)); +#else + data[1] = make_number (0); +#endif + return Flist (2, data); +} + 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. @@ -6474,6 +6509,7 @@ defsubr (&Spurecopy); defsubr (&Sgarbage_collect); defsubr (&Smemory_limit); + defsubr (&Smemory_free); defsubr (&Smemory_use_counts); #if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES