[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: structures vs. instances
- To: abegel@media.mit.edu, info-mcl
- Subject: Re: structures vs. instances
- From: straz (Steve Strassmann)
- Date: Tue, 19 Jul 1994 18:39:28 -0400
At 6:20 PM 7/19/94 -0400, abegel@media.mit.edu wrote:
>Which one takes up less memory per instance, a class instance or a structure
>with the same information?
Here's a little experiment I did. Forgetting the definition overhead,
it looks like a draw, in the trivial case 24 bytes each.
Structs can be a lot faster, but they're a lot less flexible.
Notice my use of the TIME macro, a very handy profiling tool
to inspect your program's performance.
? (defclass p1 () (a b)) ; class p1 with two slots
#<standard-class p1>
? (make-instance 'p1)
#<p1 #x1191199>
? (defstruct p2 a b) ; struct p2 with two slots
p2
? (make-p2)
#S(p2 :a nil :b nil)
? (time (dotimes (i 1000) (make-p2)))
(dotimes (i 1000) (make-p2)) took 10 milliseconds (0.010 seconds) to run.
24000 bytes of memory allocated.
nil
? (time (dotimes (i 1000) (make-instance 'p1)))
(dotimes (i 1000) (make-instance 'p1)) took 215 milliseconds (0.215 seconds) to run.
24000 bytes of memory allocated.
nil
>Are structures garbage-collected? Almost all of these structures should have
>been garbage collected along time ago.
You can always force a gc by running (gc).
Sure, they should be collected if they're no longer in use. If they're
not collected, it means you're still holding onto them (i.e. possibly
by storing them in some global list). If so, don't use global variables,
or set that global variable to NIL and that should give them their freedom.