Glenn Parker wrote:

> The Smalltalk Ruby will still need to handle more dynamic methods of
> instance variable creation:
>
> class MyClass
>    def add_ivar(name)
>      instance_variable_set(name, nil)
>    end
> end
>
> What happens to instances that have already been created when a new
> instance variable is seen by the compiler?

Just posted on that...

> There are also issues with using more memory than necessary if the
> interpreter creates every instance variable the moment it is observed
by
> the compiler.

Only in truly pathological cases - for normal numbers of instance
variables, the overhead of an external lookup table would be higher
than that of keeping a few unused slots in the body of the object.  But
of course if the compiler saw that instances of a particular class
might have up to 50 instance variables, it could choose to implement
that class with a hashtable for variables.  I'm not convinced that case
is likely enough to be worth checking and optimizing for,  but who
knows.

Avi