472,959 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 software developers and data experts.

dynamic multidimensional array question

hi, im trying to create a multidimensional array and then pass along a few funcitons.

this is the way i have created, im sure its the correct way of doing it?

// TerrainMapData is struct

TerrainMapData **TerrainData ;

TerrainData = new TerrainMapData *[TerrainWidth];

for( USHORT usLoop = 0; usLoop < TerrainLength; usLoop++ )
{
TerrainData[ usLoop ] = new TerrainMapData[ TerrainWidth ];
}

now i dont know how to pass it correctly?
would you call funcitons that would have this:

void SmoothTerrain( TerrainMapData *&TerrainData );

or would it have to be SmoothTerrain( TerrainMapData **&TerrainData );

also what would you think would be more efficient and quicker to do this?

maybe using a vector list or do it some other way, instead of passing the whole multidimensional array?
Apr 4 '08 #1
6 1902
ok, SmoothTerrain( TerrainMapData **&TerrainData ); works, im sure that means passing the whole 2d array?

but i would very much appreciate if anyone knows a more efficient was of doing this.
Apr 4 '08 #2
also do you delete the 2d array like you would with a normal dynamic array

delete [] 2d array
Apr 4 '08 #3
ok, SmoothTerrain( TerrainMapData **&TerrainData ); works, im sure that means passing the whole 2d array?
No, you are passing a reference to your multi-dimensional array. I'm not sure there's any benefit in using a reference in this case, as you may as well just use SmoothTerrain( TerrainMapData **TerrainData);

but i would very much appreciate if anyone knows a more efficient was of doing this.
Using **& or simply ** is the most efficient way to pass this around (don't quote me on this, but I'm sure both methods would result in an argument of size sizeof(unsigned int) being passed to SmoothTerrain).
Apr 4 '08 #4
also do you delete the 2d array like you would with a normal dynamic array

delete [] 2d array
Essentially, yes. Your delete needs to mirror what your new did in the first place, so:

Expand|Select|Wrap|Line Numbers
  1. for( USHORT usLoop = 0; usLoop < TerrainLength; usLoop++ )
  2. {
  3.    delete [] TerrainData[ usLoop ];
  4. }
  5.  
  6. delete [] TerrainData;
  7.  
Apr 4 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
You are not creating a 2D array. What you are doing is creating a 1D array of pointers and assigning the address of other 1D arrays o each pointer. That is not a 2D array.

Also,
TerrainMapData **TerrainData ;
Is a pointer to a TerrainData pointer. You cannot use this for the address of a 2D array.

Please read this article: http://bytes.com/forum/thread772412.html.
Apr 4 '08 #6
thanks everyone for there reply's
Apr 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Gregory L. Hansen | last post by:
I'm sure I saw this mentioned somewhere, but I can't find it. How can I dynamically allocate a multi-dimensional array in C++? My next question, if this gets figured out, is if I should use the...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
8
by: Skay | last post by:
Someone challenged me to create a dynamic multidimensional array using auto_ptr http://www.gotw.ca/gotw/042.htm Provides a good way to create a single dimensional array using an adapter. ...
2
by: Gerbus | last post by:
Hi there, I'm working in VC++ 2005 Express, and all I want is to have a dynamic multidimensional array of type Here's my code:
9
by: JoeC | last post by:
I am crating a new version of my map game and my map will be a 2d array. I had problems trying to create a 2d array dynamically, in fact C++ won't let me do it. My question is how to create the...
24
by: VijaKhara | last post by:
hi all, i am trying to create a dynamic 2D array with size N x 3 (N will be put in as a parameter) using the following code: int **xyz; int i,N; N=30000; xyz=malloc(3*sizeof(int*));
12
by: einsanic | last post by:
Dear everyone, I am new to this forum and I am realitevely new to C programming so please forgive me for any basic mistakes I'll be making. I am trying to dynamically allocate the space for...
12
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.