How do I figure out how many bytes a defclass
object has in Common Lisp?
Asked
Active
Viewed 277 times
7

Rainer Joswig
- 136,269
- 10
- 221
- 346

Paul Nathan
- 39,638
- 28
- 112
- 212
2 Answers
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
.

sds
- 58,617
- 29
- 161
- 278
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.

sds
- 58,617
- 29
- 161
- 278

Rainer Joswig
- 136,269
- 10
- 221
- 346
-
Interesting. (side explanation: I am dealing with lots of things and I'm trying to figure out how to optimize them smaller) – Paul Nathan Sep 13 '10 at 18:12
-
4Some implementations will let you profile allocation to find the hotspots. That's much a much better way to improve the footprint. – Xach Sep 13 '10 at 19:02