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

Re: size-of instance?

At 7:59 PM 5/16/95, Ken Tilton wrote:
>I know this is going to be an easy one, but I have looked a few times with
>no luck. Is there any way to get the RAM cost of a given instance? Or take
>the size-of of a class/type ala C?
>It just occurred to me I could gc-room-(setf xx make...)-gc-room, but would
>that be an accurate metric? I'll give it a go.

Here's one way:

(defmacro meter-consing (&body body)
  (let ((bytes (gensym)))
    `(let ()              ; LET here forces evaluator to compile whole form
       (let ((,bytes (ccl::%freebytes)))
           (progn ,@body)
           (format t "~&Consed ~d bytes~%" (- ,bytes (ccl::%freebytes))))))))

? (meter-consing (cons 1 2))
Consed 8 bytes
(1 . 2)