delete []array problems (program crashes)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ahmad

    #1

    delete []array problems (program crashes)

    Hi,

    I am having trouble finding the root of this problem. My program gives
    me a debugg error - I am using VC++ 6.0 - on this line delete []array,
    and I would appreciate if you could provide some help.

    here is the code...


    Note: N=4

    for(_rows=0;_ro ws<N;_rows++)
    {

    double** manor=new double*[N-1];

    for(i=0;i<N;i++ )
    *(i+manor)=new double[N-1];

    // loops to copy manor

    for(rows=1;rows <N;rows++)
    {

    int _columns=0;
    for(int columns=0;colum ns<N;columns++)
    {

    if(columns==_ro ws)
    continue;
    manor[rows-1][_columns]=m[rows][columns];
    _columns++;

    }

    }

    // code works up to this point
    // Now I want to free the allocated memory

    for(i=0;i<N-1;i++)
    delete manor[i];

    delete []manor; // it crashes on this line. I don't understand why?
    Thanks in advance,

    Ahmad

  • Gernot Frisch

    #2
    Re: delete []array problems (program crashes)


    "ahmad" <moatesim@gmail .com> schrieb im Newsbeitrag
    news:1105517728 .020441.226480@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    > Hi,
    >
    > I am having trouble finding the root of this problem. My program
    > gives
    > me a debugg error - I am using VC++ 6.0 - on this line delete
    > []array,
    > and I would appreciate if you could provide some help.
    >
    > here is the code...
    >
    >
    > Note: N=4
    >
    > for(_rows=0;_ro ws<N;_rows++)
    > {
    >
    > double** manor=new double*[N-1];[/color]

    manor can hold 3 double* now.
    [color=blue]
    >
    > for(i=0;i<N;i++ )
    > *(i+manor)=new double[N-1];[/color]

    for i=0; 1, 2, 3 -> that's 4 double*'s now. You're accessing memory
    beyond allocation.
    And that will yield at delete[] command.
    -Gernot


    Comment

    Working...