Manual work on many details, a ruby ββallocates a piece of heap to place objects in:
1 | 2 | 3 | 4 | 5
Then it moves them in order and adds them to the linked list of free objects. This makes them have the reverse order in the linked list:
freelist β NULL freelist β 1 β NULL freelist β 2 β 1 β NULL freelist β 3 β 2 β 1 β NULL freelist β 4 β 3 β 2 β 1 β NULL freelist β 5 β 4 β 3 β 2 β 1 β NULL
When distributing an object, ruby ββuses the first element in the linked list:
object = freelist freelist = object.next_free
So, now the freelist looks like this:
freelist β 4 β 3 β 2 β 1 β NULL
and further selected objects will be displayed in reverse order through small selections.
When ruby ββneeds to allocate a new piece of the heap to store more objects, you will see how object_id starts, and then run it again.
drbrain
source share