Nikolai Weibull wrote:
> I would like to figure out how much memory a certain class or object
> will/is consuming.  Is there an easy way?  Is there a hard way?
> The reason I ask is because I want to keep several hundred thousand
> instances of an object much like the following one:
>
> class A
> 	def initialize
> 		@a = @b = @c = @d = nil
> 		@e = 1
> 	end
> end
>

Instance variables are stored in a hash table associated with each
object.  See rb_ivar_set() in variable.c.  So basically each instance
will take up the size of struct RObject - which is 20 bytes on a 32bit
machine, plus the size of the hash table (see st.h), plus something
else I am probably missing.  As far as I know st.h doesn't provide any
means of calcing the number of bytes used by the hash.
Is there a way to do this?

Also, objects with no instance variables don't create a hash table to
store instance variables...

-Charlie