How big is a class in memory?
Asked Answered
Y

2

7

How do I figure out how many bytes a defclass object has in Common Lisp?

Yuu answered 13/9, 2010 at 17:8 Comment(0)
R
3

You can't do that in portable Common Lisp.

Useful could be the function ROOM. ROOM prints memory statistics and with the argument T it prints them detailed. So you may see a difference before and after some instance creations. Implementations may have specific functions, but you need to check that with the manual or with the support mailing list.

Refutation answered 13/9, 2010 at 17:54 Comment(2)
Interesting. (side explanation: I am dealing with lots of things and I'm trying to figure out how to optimize them smaller)Yuu
Some implementations will let you profile allocation to find the hotspots. That's much a much better way to improve the footprint.Travistravus
A
3

In addition to Rainer's answer, here is the answer for CLISP: macro EXT:TIMES

(defclass c () ((x) (y) (z)))
(ext:times (make-instance 'c))
                                   Permanent            Temporary
Class                         instances   bytes    instances   bytes
-----                         --------- ---------  --------- ---------
C                                     1        48          0         0
-----                         --------- ---------  --------- ---------
Total                                 1        48          0         0
Real time: 1.4E-5 sec.
Run time: 0.0 sec.
Space: 48 Bytes
#<C #x000333CF2AA0>

NB: if you evaluate defclass at the prompt, it is not compiled, so times will report some fluff in addition to c.

Abiogenesis answered 1/1, 2013 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.