[Openmcl-devel] memory

Pascal J. Bourguignon pjb at informatimago.com
Sun Apr 11 08:26:58 PDT 2010


Joakim Sandgren <joakim at joakimsandgren.com> writes:
> Are there a way to see how big in Kb  or bytes a clos object is ?

This is an ill defined notion.  The best you can do is to count the
slots.


For example:

(defclass <ex>
  (x y z))

(defun f ()
  (let ((x 'let)
        (z (list 1 2 3)))
    (let ((a (make-instance '<ex> :x x :y (format nil "Hi ~A" 42) :z z))
          (b (make-instance '<ex> :x x :y (format nil "Hi ~A" 42) :z z)))
       (values a b))))

assuming the symbol CL:LET takes 24 bytes, why should they be assigned
to A, or to B, or even half to A and half to B, since LET is already
interned in the CL package?  Or shouldn't we count X too as a user of
LET and therefore divide the size by three?  What about the other
references of LET in the program?

Same problem with the list Z.  Perhaps you would argue that it should be
split between the two objects, but what if I use F as:

(multiple-value-bind (a b) (f)
  (let ((p (slot-value a 'z))
        (q (cons 0 p)))
    (intern (slot-value a 'y))
    (values a b p q)))

shouldn't we now split it between the four?
And shouldn't the memory used by the string bound to a.y be split
between the A object and the symbol?


Only you as the programmer can define what you mean by how big a CLOS
object is.  We cannot answer your question, unless you give us YOUR own
definition of:

(defmethod size-of ((self <your-class>))
   ...)


And then we will be able to answer, well it's easy:

  (size-of your-instance)

-- 
__Pascal Bourguignon__




More information about the Openmcl-devel mailing list