CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    12

    Allocation memory ?

    How to allocate memory for 2-dimension array at run time ?



  2. #2
    Join Date
    Sep 1999
    Location
    NJ
    Posts
    1,299

    Re: Allocation memory ?

    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.

  3. #3
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: Allocation memory ?

    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....
    Using Java version on windows 1.8_51

  4. #4
    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    12

    Re: Allocation memory ?

    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.



  5. #5
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: Allocation memory ?

    You are better off looking at link lists
    i suggest you look at
    http://www.codeguru.com/cgi-bin/bbs/...&Number=296877

    Share what you know and ask what you dont....
    Using Java version on windows 1.8_51

  6. #6
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    47

    Re: Allocation memory ?

    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?



  7. #7
    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    12

    Re: Allocation memory ?

    THANKS for your KIND HELP.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured