[Mono-devel-list] Zero Length Arrays

Jonathan Gilbert 2a5gjx302 at sneakemail.com
Mon Jan 12 20:40:22 EST 2004

Hold on, though -- how many levels of indirection are there? I thought
there was one more level than you are implying. There is a table of object
IDs, and each entry in the table refers to a different object. If locking
applied to IDs, then multiple IDs could point to the same actual
(immutable) object with no side-effects. However, I don't know enough about
the runtime to be sure of any of this. For instance, the JIT might not
actually use object IDs, which means that locking would have be done
directly on the objects, making the optimization actually impossible. I
just don't know the details :-)

I'm still not sure that the optimization is really necessary, though :-)


At 11:13 AM 12/01/2004 +0100, you wrote:
>Ben Maurer wrote:
>> So, today, I realized that there is a VERY simple solution. In
>> mono_array_new, if it finds that it will be creating a zero length
>> array, it should used a cached zero length array.
>ECMA says:
>"The newarr instruction pushes a reference to a *new* zero-based,
>one-dimensional array" (my emphasis).
>This optimization is not allowed. Plain and simple.
>Piers Haken wrote:
>> What about locking?
>This is why the optimization isn't legal. The following pattern is
>should work:
>object myLock = new object[0];
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com

More information about the Mono-devel-list mailing list