How do I figure out how many bytes a defclass
object has in Common Lisp?
How big is a class in memory?
Asked Answered
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.
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
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
.
© 2022 - 2024 — McMap. All rights reserved.