Re: arrays = pointers?



On Fri, 02 Mar 2007 00:15:22 +0800, Zytan <zytanlithium@xxxxxxxxx> wrote:

No, it's just a pointer.

This would explain why C# is fast.

Except when garbage collecting, of course. With the application having just a single pointer, that means that when the GC relocates something, it needs to go around updating all of the pointers that refer to it. If the application had to do the double-dereference, then the GC would be able to just update a single pointer and be done.

I presume that the thought is that garbage collection can happen infrequently enough, and at least to some extent in the background, that speeding the common case execution nets a gain. Of course, it does also create synchronization issues, since while an object is being relocated and all those pointers are being updated, .NET needs to ensure that no code using that reference tries to access it.

Performance might be better the way .NET does it, but certainly the old Mac-style "handle" paradigm was much simpler, and required much less memory overhead (and back then, with memory space always being at a premium, reducing data structure and code size was always the highest priority). :)

If it were doubly indirection, then I think we'd see it being slower
than it is.

Execution of one's own code would definitely be slower, I agree. But garbage collection could be much faster. It's just a matter of optimizing for the most effective case (one hopes that in this scenario, the .NET designers got it right...I assume they did :) ).

Pete
.


Loading