<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>sizeof is very handy </div><div><br></div><div>There is a very simple version of the SIZEOF method in here: <a href="http://code.google.com/p/xmlisp/source/browse/trunk/XMLisp/sources/Lisp%20User%20Interface/specific/Mac%20CCL/memory.lisp">http://code.google.com/p/xmlisp/source/browse/trunk/XMLisp/sources/Lisp%20User%20Interface/specific/Mac%20CCL/memory.lisp</a></div><div><br></div><div>some examples:</div><div><br></div><div><div>(defgeneric SIZEOF (Object)</div><div>  (:documentation "the size of object in memory. Object can be instance or type name"))</div><div><br></div><div><br></div><div>(defmethod SIZEOF ((Self float)) 4)</div><div>(defmethod SIZEOF ((Self double-float)) 8)</div><div>(defmethod SIZEOF ((Self fixnum)) 4)</div><div><br></div><div>(defmethod SIZEOF ((Type (eql 'float))) 4)</div><div>(defmethod SIZEOF ((Type (eql 'double-float))) 8)</div><div>(defmethod SIZEOF ((Type (eql 'fixnum))) 4)</div><div><br></div><div>(defmethod SIZEOF ((Self macptr))</div><div>  #-windows-target (#_GetPtrSize Self)</div><div>  #+windows-target (#_HeapSize (#_GetProcessHeap) 0 Self))</div><div><br></div><div><br></div><div>works for Mac/PC but needs fixing for 64/32 bit</div><div><br></div><div>Alex</div></div><div><br></div><br><div><div>On Apr 12, 2010, at 12:22 PM, Bill St. Clair wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>It seems to me that what you need would be partially your own recursive<br>data structure walker and partly a CCL-provided SIZEOF generic function.<br>The SIZEOF generic function would take a single argument and return the<br>number of bytes used by that object alone, but not anything it<br>references. Your function would walk one of your data structures,<br>calling sizeof on each Lisp object that you consider to be part of that<br>one user-level data structure and summing all the results.<br><br>I sent in my last reply the code for SIZEOF on a CCL standard CLOS<br>instance. Adding a full-featured SIZEOF generic function to CCL would<br>likely be useful, and is probably not very difficult. You could do it<br>yourself with a little routing around in the CCL source code. Or maybe<br>somebody else on the list would like to make a portable version.<br><br>-Bill<br><br>On 4/12/10 10:16AM, Joakim Sandgren wrote:<br><blockquote type="cite">In my case I have an object that contains all structures and data for a<br></blockquote><blockquote type="cite">whole musical composition.<br></blockquote><blockquote type="cite">parts, measures, notes, pitchvalues mapping tables...<br></blockquote><blockquote type="cite">It would be good to be able to see the "footprint" of different types of<br></blockquote><blockquote type="cite">solution.<br></blockquote><blockquote type="cite">as you are always confronted with either big size and high speed, or<br></blockquote><blockquote type="cite">smaller size and more calculations and then slower speed.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">sincerely<br></blockquote><blockquote type="cite">joakim<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Le 12 avr. 10 à 06:45, Gary Byers a écrit :<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">When people ask questions like this, they usually means something<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">like "what's the total size of this object, plus the size of all<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">things that<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">it transitively and uniquely references ?"<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Another way of asking that is to ask "if the object in question became<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">garbage, how<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">much memory would be freed by the GC ?"<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">(let* ((obj (make-instance ...)))<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">(gc)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">(let* ((with-obj (%precise-size-of-allocated-memory-at-the-moment)))<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">  (setq obj nil)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">  (gc)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">  (let* ((without-obj (%precise-size-of-allocated-memory-at-the-moment)))<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">    (- with-obj without-obj))))<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">There's no such function as the one that I'm calling<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">%PRECISE-SIZE-OF-ALLOCATED-MEMORY-AT-THE-MOMENT; it's very hard to<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">measure this in CCL (because of threads and because of other issues.)<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> We're also assuming that OBJ is the only thing that becomes garbage<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">between the two GCs, and we're assuming that that object isn't sitting<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">in some machine register even after we set the variable OBJ to NIL.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> Neither of those assumptions is valid.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">I don't want to say that there's no reliable way to answer this<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">question in general, but it's much, much harder to answer than it<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">might appear to be at first glance.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">There are some heap-analysis utilities described at<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><<a href="http://trac.clozure.com/ccl/wiki/MemoryUtils">http://trac.clozure.com/ccl/wiki/MemoryUtils</a>> (some of them are<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">currently x8664-Linux-specific); none of them try to answer this<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">question, but they do try to answer some similar questions.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">--On April 11, 2010 4:50:23 PM +0200 Joakim Sandgren<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><<a href="mailto:joakim@joakimsandgren.com">joakim@joakimsandgren.com</a> <<a href="mailto:joakim@joakimsandgren.com">mailto:joakim@joakimsandgren.com</a>>> wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Hi,<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Are there a way to see how big in Kb  or bytes a clos object is ?<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">sincerely<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">joakim<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">Joakim Sandgren<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">joakim sandgren musik<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">42, rue de Maubeuge<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">75009 Paris<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">France<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite">+33 (0)1 45 26 43 90<br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><a href="mailto:info@joakimsandgren.com">info@joakimsandgren.com</a> <<a href="mailto:info@joakimsandgren.com">mailto:info@joakimsandgren.com</a>><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><a href="http://www.joakimsandgren.com">http://www.joakimsandgren.com</a><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Joakim Sandgren<br></blockquote><blockquote type="cite">joakim sandgren musik<br></blockquote><blockquote type="cite">42, rue de Maubeuge<br></blockquote><blockquote type="cite">75009 Paris<br></blockquote><blockquote type="cite">France<br></blockquote><blockquote type="cite">+33 (0)1 45 26 43 90<br></blockquote><blockquote type="cite"><a href="mailto:info@joakimsandgren.com">info@joakimsandgren.com</a> <<a href="mailto:info@joakimsandgren.com">mailto:info@joakimsandgren.com</a>><br></blockquote><blockquote type="cite"><a href="http://www.joakimsandgren.com">http://www.joakimsandgren.com</a> <<a href="http://www.joakimsandgren.com/">http://www.joakimsandgren.com/</a>><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">Openmcl-devel mailing list<br></blockquote><blockquote type="cite"><a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br></blockquote><blockquote type="cite"><a href="http://clozure.com/mailman/listinfo/openmcl-devel">http://clozure.com/mailman/listinfo/openmcl-devel</a><br></blockquote>_______________________________________________<br>Openmcl-devel mailing list<br><a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br>http://clozure.com/mailman/listinfo/openmcl-devel<br></div></blockquote></div><br><div>
<span class="Apple-style-span" style="font-size: 12px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Prof. Alexander Repenning</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><br class="khtml-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px">University of Colorado</p><p style="margin: 0.0px 0.0px 0.0px 0.0px">Computer Science Department</p><p style="margin: 0.0px 0.0px 0.0px 0.0px">Boulder, CO 80309-430</p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><br class="khtml-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">vCard: <a href="http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf">http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf</a></font></p><br class="Apple-interchange-newline"></span></span></span>
</div>
<br></body></html>