Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / August 2003

Tip: Looking for answers? Try searching our database.

Multidimentional Arrays   ATT: David Notario

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andre - 10 Aug 2003 18:14 GMT
Hi,

David, hope you read this.. I wanted to ask you if the next version of
the framework changes the way multidimentional arrays are indexed (i.e
via method calls and not by calculating positions by an offset)? Is
there any particular reason why multidimentional arrays were implemented
this way? Thanks

-Andre
Rico Mariani [MSFT] - 12 Aug 2003 20:28 GMT
I'm sorry Andre, I totally missed the point of your message.  You weren't
asking if we were going to offer abstract indexing at all, you were
wondering if the helper functions used to compute the offset in the
multidimension case were eliminated.

And sadly, I don't know, but even if I did, I really shouldn't talk about
new ways we do stuff.

Wow was that ever useless... let me see if I can't get at least some info on
the helpers for you.

Please disregard my earlier posting as it was totally not addressing your
question.

   -Rico

> Hi,
>
[quoted text clipped - 5 lines]
>
> -Andre
Andre - 12 Aug 2003 21:56 GMT
That's ok Rico :) Thanks for wanting to answer though. It's just that
multidimentional arrays (rectangular arrays to be precise) can easily be
indexed using an offset. However, the produced IL reveals that this is
not the case. These arrays are indexed using 'set' and 'get' methods:

  i[0,0] = 13;    produces:
  IL_000f:  call       instance void int32[0...,0...]::Set(int32,
                                                           int32,
                                                           int32)

  j = i[0,0];     produces:
  IL_0017:  call       instance int32 int32[0...,0...]::Get(int32,
                                                            int32)

I was just wondering why they're implemented this way (and thus are
extremely slow compared to their counterpart, jagged arrays). Couldn't
they be indexed using a simple offset? Will this be kept in later
versions? Thanks :)

cheers,

-Andre

> I'm sorry Andre, I totally missed the point of your message.  You weren't
> asking if we were going to offer abstract indexing at all, you were
[quoted text clipped - 21 lines]
>>
>>-Andre
David Notario - 13 Aug 2003 06:52 GMT
Hi Andre.

The JIT knows about those helpers and treats them as an intrinsic. We
currently inline 2 and 3 dimensional arrays, so the code is generated inline
and optimizable (as in removing range checks, and potentially using a single
offset), so we could potentially end up generating optimal code (we could do
it for more dimensions, but you could end up have more bloated code, and 4+
dimensional arrays are not so common, so we go through the helper for
those). Unfortunately, I've noticed that we're not so good removing those
range checks in the 2 and 3 dimensional case as we could and I'm not
convinced this will be a high priority item for us. Let us know how
important this is for you.

We cannot use an offset (at least in IL), because we have to do range
checking. I dont know why they didn't implement the Get and Set as a new IL
instructions (a good argument is that probably they didnt like the idea of
having IL instructions having a variable number of arguments, and then
decided to use a helper. I dont think this matters, though, the JIT can
treat them as intrinsics). If you want to use a single offset, use single
dimensional arrays and calculate it yourself (that's what I would do if
writing code)

Signature

David Notario
Software Design Engineer -  CLR JIT Compiler
http://xplsv.com/blogs/devdiary/

> Hi,
>
[quoted text clipped - 5 lines]
>
> -Andre
Andre - 13 Aug 2003 08:32 GMT
Thanks a lot David.

Actually you're right about calculating an offset using a single
dimensional array (and that's what I'm currently doing) and normally I'm
not sure if I would calculate an offset in a 2 dimensional array, but
was only wondering why it's not being done this way down at the IL
level.. but I got my answer :)

I translated some numerical code written in C to C# and was using
rectangular arrays (instead of sparse arrays) and noticed a performance
hit. I thought maybe it's because of the get set method calls, but as
you say, they're inlined and are treated as intrinsics.. so they
shouldn't matter, and I guess it really must be due to bounds checking.
On very large arrays, I see quite a large difference if I choose to use
rectangular arrays. Does this imply that the IL instructions you have
for jagged arrays (ldelem and stelem) aren't any different from the Get
and Set methods in regard to performance (or at least they shouldn't be
any different)? They should essentially perform equally well but because
currently range checks aren't properly eliminated for rectangular
arrays, we end up with rectangular arrays performing badly?

Thanks again for the clarification David, I can sleep well tonight :)

cheers,

-Andre

> Hi Andre.
>
[quoted text clipped - 17 lines]
> dimensional arrays and calculate it yourself (that's what I would do if
> writing code)
Andre - 13 Aug 2003 08:52 GMT
.... snip ....

> Let us know how important this is for you.

One main issue is CLS compliance.. I read someplace that jagged arrays
aren't (?) and so for my arrays to work 'across languages', I may need
to use rectangular arrays. For that reason performance may be an issue.

Thanks

-Andre

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.