Jump to content
  • Advertisement
Sign in to follow this  
DarkRonin

Two dimensional array question

This topic is 658 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

Hi Guys,

 

Just wondering if it is possible to somehow create and initialise a 2D array with varying sized data.

 

Something like this;

 

float item[][0] = { 1.0, 9.0, 3.5 };
float item[][1] = { 9.5, 1.2, 9.9, 7.7, 2.4, 1.8 };

 

And then access the data how ever I wise after that, being aware to check sizeof(item[x][y]) obviously.

 

Is this sort of thing possible?

 

Or is a std::vector better for this sort of thing?

 

Thanks in advance.

 

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

Take a step back... what are you trying to achieve? 

 

Will the size of the individual rows change, or will it be allocated upfront? You could make it a 1d array with some clever indexing (hidden behind a class).

 

There are lots of ways of doing this... in terms of simplicity a vector of vectors (std::vector<std::vector<float>>) will achieve what you want with a minimum of fuss and be almost guaranteed to be leak free. But it might not be optimal for your scenario (if performance is a consideration).

Share this post


Link to post
Share on other sites

Hi there and thanks for the reply.

 

Each array will be static. Essentially, I want to store frame animation and each frame is a 1D array. So, I want to be able to increment or manually choose what frame I want but have it in the form of frame[n]. 'n' being the frame number.

Share this post


Link to post
Share on other sites

Thanks Alvaro. I was driving home from work and I was thinking of a solution along very similar lines to what you have there.

 

I'll have a play around and see what I can come up with. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!