Hi
I am studying arrays... So i have a simple question.. I better to use one dimensional arrays or 2 dimensinal arrays? And why? I mean who is faster and why? Wich is better to use for compare the valus of 2 equal arrays??
Hi
I am studying arrays... So i have a simple question.. I better to use one dimensional arrays or 2 dimensinal arrays? And why? I mean who is faster and why? Wich is better to use for compare the valus of 2 equal arrays??
It depends on the data. If you need to locate the X-Y location of a pixel in a window, that's a 2-d array. Bitmaps are composed of 3 colors per pixel, so bitmaps are 3-d arrays.
AFAIK, there is no speed difference. Physical memory is one-dimensional and multi-dimensional arrays are a conceptual abstraction.
1D arrays can be usefull for holding filenames for image files for a game. You can than use a 'for' loop to search through the array and load the images into memory. 2D arrays can be used for displaying a chess/checker game in a console app. They can also be used for graphical games, such as 'Breakout', to display a map. An array of type 'int' will be filled with numbers, which correspond to certain color tiles. There are many uses for both types, and again, depends on the situation.
Videogame Memories!
A site dedicated to keeping videogame memories alive!
http://www.videogamememories.com/
Share your experiences with us now!
"We will game forever!"
They are really the same neither is faster. It's just a style difference. 2D arrays are stored in continuous memmory, just like 1D arrays.
You want your code to be easy to read, so use which ever makes sence.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
It is however of note to mention that there is no such thing as a multidimensional array in C++. A 2D array is in fact an array of arrays. It is still a unidimensional array, only each element is storing an array. A 3D array is in fact an array storing arrays each of them storing an array. A 4D array is... ad aeternum.
Code:/* An array called myarray with 2 elements. Each element is an array of 3 ints. */ int myarray[2][3];
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Not true.They are really the same neither is faster. It's just a style difference. 2D arrays are stored in continuous memmory, just like 1D arrays.
How do you suppose indexing into a 2D array at an arbitrary offset is done without using a multiply?
??