CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2003
    Location
    India
    Posts
    94

    deleting 2-Dimensional Arrays

    I am allocating memory for a 2 dimensional array as follows..how do I delete it?


    double (*e)[3] = new double[4][3]

    Regards
    mgore

  2. #2
    Join Date
    Sep 2002
    Location
    Yerevan, Armenia
    Posts
    78

    Suggestion

    I think you need to write something like this


    for(int i = 0; i < 4; i++)
    delete [] e[i];

    delete [] e;

  3. #3
    Join Date
    Feb 2003
    Location
    India
    Posts
    94
    I am doing this but in Visual Studio while debugging I am getting a dialog box with the following message:

    User breakpoint called from code at ..

  4. #4
    Join Date
    Mar 2001
    Posts
    168
    A 2D array is handled internally like a 1D array, except that the compiler translates your calls to [1][5] to (max_dim*1 + 5), so to speak.
    delete [] e; should actually do the trick.

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Why do you not use the standard vector template instead? It is much easier and handles the memory on its own...

    For further information take a look at this FAQ...

  6. #6
    Join Date
    Feb 2003
    Location
    India
    Posts
    94
    would have loved to use vector of vectors .. but the APIs which I need to call take a 2-Dimensional array of doubles, the number of columns are constrained.. and number of rows will keep varying.. so I need to allocate memory from the heap...

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