Function: memory-info
memory-info is a function defined in alloc.c.
Signature
(memory-info)
Documentation
Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP).
All values are in Kbytes. If there is no swap space,
last two values are zero. If the system is not supported
or memory information can't be obtained, return nil.
If default-directory is remote, return memory information of the
respective remote host.
Probably introduced at or before Emacs version 29.1.
Source Code
// Defined in /usr/src/emacs/src/alloc.c
{
Lisp_Object handler
= Ffind_file_name_handler (BVAR (current_buffer, directory),
Qmemory_info);
if (!NILP (handler))
return call1 (handler, Qmemory_info);
#if defined HAVE_LINUX_SYSINFO
struct sysinfo si;
uintmax_t units;
if (sysinfo (&si))
return Qnil;
#ifdef LINUX_SYSINFO_UNIT
units = si.mem_unit;
#else
units = 1;
#endif
return list4i ((uintmax_t) si.totalram * units / 1024,
(uintmax_t) si.freeram * units / 1024,
(uintmax_t) si.totalswap * units / 1024,
(uintmax_t) si.freeswap * units / 1024);
#elif defined WINDOWSNT
unsigned long long totalram, freeram, totalswap, freeswap;
if (w32_memory_info (&totalram, &freeram, &totalswap, &freeswap) == 0)
return list4i ((uintmax_t) totalram / 1024,
(uintmax_t) freeram / 1024,
(uintmax_t) totalswap / 1024,
(uintmax_t) freeswap / 1024);
else
return Qnil;
#elif defined MSDOS
unsigned long totalram, freeram, totalswap, freeswap;
if (dos_memory_info (&totalram, &freeram, &totalswap, &freeswap) == 0)
return list4i ((uintmax_t) totalram / 1024,
(uintmax_t) freeram / 1024,
(uintmax_t) totalswap / 1024,
(uintmax_t) freeswap / 1024);
else
return Qnil;
#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT, not MSDOS */
/* FIXME: add more systems. */
return Qnil;
#endif /* HAVE_LINUX_SYSINFO, not WINDOWSNT, not MSDOS */
}