Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


switching from 1d to 2d

This topic is 5450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im getting ready to wrap all the code from my terrain application into a class, and i really would like the luxury of having a 2d array instead of a 1d array... first i want someone to either support or kill the following concept: 1d array is faster than 2d array? if you support it, then no need to switch to 2d array... if you kill it, then ill need to switch to 2d array''s. About 6 months ago, i could have told you ALL about 2d array''s, so im not a beginner, but i forget the syntax basically (passing a 2d array, declaring a 2d array, initializing and deinitialzing otherwise known as creating and freeing the memory it holds) any one have a quick refresher, or maybe a short tutorial that''s not aimed at newbies ( i dont want to spend 2 hours reading about why array''s work, how they work, blah blah, i already know that i just forget the syntax) id greatly appreciate the help... I googled 2d array and multi dimensional array, but im not finding what im looking for

Share this post

Link to post
Share on other sites
All a 1d array is is a pointer adress and some offsetting depending on the location needed. A 2d array simply has a slightly more complicated way of calculating the offsets. Its unlikely to cause any noticable difference.

But.. have you profiles it? If you havn''t then you''re already wasting time.

Share this post

Link to post
Share on other sites
On the other hand there is another way of creating a 2D array in C which goes like
 **var= new *[PRIMARYDIMENSION];  
folowed by a per-index initialization of each element of the primary dimension.


  • Indexing is very intutive
    x = var[u][v];  

  • the 2D array needs not to be square

Potentially slower for random access, but if well used still as fast for sequential access along the secondary dimension.

[edited by - Dreamforger on October 23, 2003 5:38:12 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!