Jump to content
  • Advertisement
Sign in to follow this  
CzarKirk

Dynamic Memory

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

Hey there. I'm fairly competant with C++ but rather new to dynamic memory. Basically I am making a minesweeper game which, as you know, can be of any size set by the user. So that's normal arrays out. The problem with ordinary dynamic memory is it's 1 dimensional, although I suppose I could find mathmatical ways to find out the correct squares. So basically, does anyone have any advice and hints as to the best way to create a minesweeper board of an unknown size? I will be needing to send this board as a parameter to other parts of the program. Thanks. Neil.

Share this post


Link to post
Share on other sites
Advertisement
When you think "C++" "array" and "dynamic", the next word you think should be "std::vector".

In this case, a std::vector of std::vectors.

E.g.

typedef std::vector<Cell> BoardRow;
typedef std::vector<BoardRow> Board;

Share this post


Link to post
Share on other sites
I think the easiest way here is just to allocate a standard array on dynamic memory.

// field dimensions
int width, height;
// field access coords
int x, y;

// create field array
int *field = new int[ width * height ];
// access field square
field[ x + y * width ];
// delete field array
delete[] field;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!