Click to See Complete Forum and Search --> : Allocation memory ?


Anuj Garg
October 29th, 2001, 06:22 AM
How to allocate memory for 2-dimension array at run time ?

James Curran
October 29th, 2001, 06:44 AM
Think carefully before you answer this question: How many dimensions must be dynamic at runtime?

If the number of columns is fixed, while the number of row must vary (which is the case about 95% of the time), the answer is fairly simple.

If both the number of rows and the number of columns must vary, it's a lot more difficult.



Truth,
James
http://www.NJTheater.com
http://www.NovelTheory.com
I don't do it for the points (OK, maybe I do), but rating a post is a good way for me to know if I helped.

Saeed
October 30th, 2001, 06:22 PM
How about

int **array
int nRows=5;
int nCols=3;

array= new int*[nRows];

for ( int index = 0; index < nRows; index++ )
{
array[index] = new int[nCols];
}

Now is this what you were looking for?

Share what you know and ask what you dont....

Anuj Garg
October 30th, 2001, 11:40 PM
Yes Saeed, I want to ask same thing but in different way. I do not want to specify any size of an array.
Suppose I have 'n' values to insert to an array, now at run time, program should automatically expand the size of an array and store new value.

Saeed
October 31st, 2001, 03:27 PM
You are better off looking at link lists
i suggest you look at
http://www.codeguru.com/cgi-bin/bbs/wt/showpost.pl?Board=vc&Number=296877

Share what you know and ask what you dont....

Virtuality
October 31st, 2001, 04:22 PM
You don't give us any detail so I won't give you any :-) but if the standard C++ library doesn't have something for you (list, array, vector, etc.) then I'll go heave. Focusing on allocating memory worries me, are you sure you're thinking in C++ and not C? :)

Anuj Garg
November 1st, 2001, 06:31 AM
THANKS for your KIND HELP.