Can I measure how much memory an object consumes?
- From: Mathias Dahl <mathias.dahl@xxxxxxxxx>
- Date: Tue, 3 Jun 2008 00:38:32 -0700 (PDT)
I am developing a small web application using Hunchentoot. It is
currently running in a VMWare instance with Ubuntu as the guest OS and
Windows XP as host. Because it runs on my machine I have given the
instance 300 MB memory.
Now I am thinking of logging the latest X requests in a global
variable, to make debugging easy if error reports from users comes
in. I was thinking of maybe saving the last 100 or so, but due to the
limited memory I have, I would like to know if there is a way for me
to calculate or measure how much memory these 100 request objects will
consume, to see if this is feasible. Is there? Other than running
`top' and
watching the memory consumption increase, that is.
I am using the latest SBCL available in Ubuntu 8.04.
Thanks!
/Mathias
PS. To keep only the last X requests stored, I wrote a couple of
"ring" functions. If anyone have suggestions on a better data
structure to save this in, please let me know:
(defun make-ring (len)
(cons 0 (make-array len)))
(defun ring-push (ring item)
(let ((vec (cdr ring))
(idx (car ring)))
(setf (aref vec idx) item)
(setf (car ring) (mod (1+ idx) (length vec)))))
(defun ring-pop (ring)
(let ((vec (cdr ring))
(idx (car ring)))
(setf (car ring) (mod (- (+ idx (length vec)) 1) (length vec)))
(aref vec (car ring))))
(defvar *requests*)
(setf *requests* (make-ring 10))
And I call it like this:
(ring-push *requests* *request*)
.
- Follow-Ups:
- Re: Can I measure how much memory an object consumes?
- From: Thomas A. Russ
- Re: Can I measure how much memory an object consumes?
- From: David Lichteblau
- Re: Can I measure how much memory an object consumes?
- From: Edi Weitz
- Re: Can I measure how much memory an object consumes?
- Prev by Date: Re: Are we close to a Lisp boom ?
- Next by Date: Re: Lisp, 50th Birthday
- Previous by thread: Re: Attribute Grammar Compilers
- Next by thread: Re: Can I measure how much memory an object consumes?
- Index(es):
Relevant Pages
|
|