ruby - Object memory allocation -
I'm wondering how memory allocation works in Ruby.
In Ruby, we can open the definition of a square and add more example variables / methods In this case, new objects will require more memory than existing objects. For example, we have a definition of the following category:
class MyClass def myMethod @ a = 5 end-end code> we MyClass
:
M = MyClass.new m.mymethod
At this point, m
Some memory will be allocated Now, we open the definition of class and add another example variable b
.
Preclass MyClass def mySecondMethod @b = 5 End End
This new method is mySecondMethod
and the example variable b < / Code> are also available in current version
m
of Myclass
. mySecondMethod
m.mySecondMethod
m
, or do new types of signals appear in new allocated memory? "Itemprop =" text "> The answer depends on the actual implementation here I think you are asking.
Ruby is allocated on objects. There is no concept when talking about allocation.
The stack is divided into pages , 16 kb in each, each page is fixed size < / Em> is placed in the slot which can hold the Ruby object. One page ~ 408 ob The jacks can hold, because each object (which is a straight) stays in 40bytes.
All of this is managed by VM (ie.)
Source:
About your example < / Strong>, variables only hold references for objects, so for a myClass
object m
actually digits . MyClass
backs up internally, s String ( RClass
), the user-defined methods like #mySecondMethod
and examples of its objects a pointer to the table with the names of frequency.
Each object (which is the default root of all objects, since it is backed up) internally.
The method to see the dynamic nature of the language and method on runtime is that the newly defined # mySecondMethod
is available.
Comments
Post a Comment