4 ms·
I tried with a "pure" Array - for Ruby it's 1Mb for 100 000 elements EDIT: and for Hash with h[i] = i, it's ~6Mb
by InfernalH 15y ago
I tried with a "pure" Array - for Ruby it's 1Mb for 100 000 elements
EDIT: and for Hash with h[i] = i, it's ~6Mb
- masklinn 15y agoDoes that account for the size taken by the integers themselves?
- jeltz 15y agoI assume so. If the integers fit in 31 or 63 bits, depending on your architecture, they are inlined in the pointer.
- masklinn 15y agoOK (because that's not the case in CPython, I think)
- jeltz 15y agoYeah, I too am pretty sure that CPython does not inline integers in the pointers. And from a quick glance at the source code I saw nothing such. Inlining integers in pointers by shifting up and adding 1 is a quite common trick though and I have seen it in more programming language implementations than MRI. I think at least some Prolog implementation and older versions of Spidermonkey (newer versions use a similar trick with doubles).
- masklinn 15y ago> Inlining integers in pointers by shifting up and adding 1 is a quite common trick though and I have seen it in more programming language implementations than MRI. Yeah, I know about it, I just did not think MRI had bothered with it anymore than CPython.
- vidarh 15y agofalse, true, nil, Symbol's and Fixnum's are all special cased with typetags in MRI.
- cygx 15y agoInlining integers in pointers by shifting up and adding 1 is a quite common trick though and I have seen it in more programming language implementations than MRI This trick was already used in Smalltalk-80, btw. A more recent variant of this is NaN tagging, made popular by LuaJIT.