Skip to main content
gamedev.net
🔒 Locked

Multi Dimensional Array Speed Comparison

Started by LowCalorieSoftDrink Jul 21, 2003 at 5:37 PM 4 replies 950+ views
Original Post
LowCalorieSoftDrink
LowCalorieSoftDrink
Im currently writing a software rasterizor so speed is of ultimate important... so my question, is defining a single array faster than a multidimensional array. Because the buffer is resizeable i am dynamically allocating the memory, i realise there is the extra overhead involved with indexing a single dimensioanl array in a multi dimensional manner, ie. Array[x + width*y], but is that quicker than Array[x][y] Hrm, yes, thanks
Lantz
Lantz
It''s most likely exactly the same. You could check the assembly output.
RamboBones
RamboBones
Yep accessing like that is the same. I tend to prefer the single dimensional because you can do more optimizations with it than with the multi dimensional, at least *I* can do more.
31337
31337
While perhaps the look up time will be similar, if you do the multi dimensional lingo, your going to need to store pointers you wouldn''t have had to if you did it the other way
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/
way_out_west
way_out_west
Speed isn''t an issue here because all multidimensional arrays of built in types in C++ are, under the hood, implemented as unidimensional arrays. In the end, the compiler to refers to the Array elements using a similar index/subscript scheme as you do - [x + width*y].

So no, I suggest you continue using multidimensional arrays. After all (In my opinion), they are much easier to understand.
VolkerG
VolkerG
That might be true for static arrays, but there is no way to allocate a multidimensional array with a single new in a single chunk of memory.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.