Вопрос

I seem to be getting negative values for object_id for some objects. Is this correct? If so, when is a ruby object's object_id negative?

Это было полезно?

Решение

https://github.com/ruby/ruby/blob/ruby_1_9_3/gc.c#L3171 should answer your question in full, technical detail, but ultimately because the object pointer is modified in a variety of ways, then returned as a signed integer.

Другие советы

Integers have odd object_id's, and the other objects use the even object_id's. For this to work, negative integers have (odd) negative object_id's - there is no room elsewhere. The even negative object_id's are free to be used for other objects.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top