Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi-Dimensioning Dynamic Memory Management Class

Status
Not open for further replies.

vanleurth

Programmer
Sep 1, 2001
156
US
Hi I'm new to Visual C++, previously I was able to write a function that dynamically allocate memory for multidimensional arrays [][][]. How can I define a class that will do the same job of returning a pointer to different memory space for different, for example;
*(int) - for a single dim
** (int) - for double dim
*** (int) - for triple dim
 
Do not use multidimensional indexing. You can, of course, allocate single-dimensional arrays for each row, then arrays of pointers for sets of rows, and so on. More simple is allocation of a single-dimensional array

p = new int[num_of_columns*num_of_rows];

and access elements through p[row*num_of_columns + column]

<a href=&quot;thread116-202306 about arrays</a>
 
Sorry, you can simply define
int (*array_ptr)[3][4];
allocate
array_ptr=new(int[2][3][4]);
and access elements as
array_ptr[j][k]

[a href=&quot;thread116-202306 arrays[/a]
 
Oh, that bloddy server...
The right text:

Sorry, you can simply define
int (*array_ptr)[3][4];
allocate
array_ptr=new(int[2][3][4]);
and access elements as
array_ptr[j][k]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top