Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Array implement...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 4222 of 4370
Post > Topic >>

Array implementation in C

by Pranav Negandhi <pranav@[EMAIL PROTECTED] > Jul 29, 2008 at 12:59 PM

This query was inspired from the essay at 
http://www.artima.com/cppsource/how_to_go_slow.html.
If you look at the 
section regarding Thra****ng, about half-way through the page you'll see 
the following -

-- Start extract
Consider some code that sums a square array:

    for (row = 0; row < N;, ++row)
       for (col = 0; col < N; ++col)
          sum += A[row][col];

Or you can do it the other way round:

    for (col = 0; col < N; ++col)
       for (row = 0; row < N; ++row)
          sum += A[row][col];

-- End of extract

 From what I understand, the array int A[8][3] is stored as follows -

|0|1|2|3|4|5|6|7| - row 0
|0|1|2|3|4|5|6|7| - row 1
|0|1|2|3|4|5|6|7| - row 2

Later in this article, the author says - "On my machine summing a 
billion bytes row-wise takes 9 seconds, whereas summing them column-wise 
takes 51 seconds. The less sequential your data access, the slower your 
program will run."

I'm a little confused by this line. Does he mean that the fastest 
sequential access to each element would be -

A[1][0];
A[2][0];
A[3][0];
A[1][1];
A[2][1];
A[3][1];
A[1][2];
A[2][2];
A[3][2];
A[1][4];
..
..
....so on

I am aware that this is not the best approach to optimization and I 
would get better returns through a different algorithm, et al. This is 
simply a C-newbie's query regarding some aspect of the language 
implementation. Please be gentle.

..p
 




 6 Posts in Topic:
Array implementation in C
Pranav Negandhi <prana  2008-07-29 12:59:01 
Re: Array implementation in C
Richard Heathfield <rj  2008-07-29 08:00:24 
Re: Array implementation in C
Francis Glassborow <fr  2008-07-29 11:04:20 
Re: Array implementation in C
"Jim Langston"   2008-07-29 04:58:48 
Re: Array implementation in C
Pranav Negandhi <prana  2008-07-29 18:12:43 
Re: Array implementation in C
Barry Schwarz <schwarz  2008-07-29 09:16:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 12:46:06 CST 2008.