Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current memory usage in Lisp

I need to find out, from within a Common Lisp program, how much memory is currently being used.

I'm given to understand there is no portable method (the standard function room prints the information to standard output in text form instead of returning it as a value), but sb-kernel:dynamic-usage works in SBCL.

What are the equivalents in other Common Lisp implementations? Or is there another way to solve this problem I should be looking at?

like image 606
rwallace Avatar asked Nov 16 '10 13:11

rwallace


2 Answers

It may not help you much, but anyway:

You can capture the output of (room) and parse it.

(with-output-to-string (*standard-output*)
  (room))

Above returns a string with the output of ROOM.

Additionally it may help to request the memory size of the process via an external call to a standard unix command (if you are on Unix).

like image 143
Rainer Joswig Avatar answered Oct 19 '22 15:10

Rainer Joswig


For things which virtually every implementation supports, but not in the same way (because it's not in CL), one common approach is to make a library called trivial-whatever.

If you started a package like trivial-memory, and supplied the first implementation, I'm sure we could get everybody to contribute the function for their own favorite Lisp compiler in short order. :-)

like image 31
Ken Avatar answered Oct 19 '22 16:10

Ken