Someone knows how can I destroy a 3D vector?

Discussion in 'C++' started by joseantonio, Jan 13, 2005.

  1. joseantonio

    joseantonio Guest

    Hi all,

    I am novice in C++, (basically, novice using OOP). I am developing an
    application where I use a vector 3D defined as

    vector< vector< vector<double> > >
    Ez(NFILAS, vector< vector<double> >(NCOLUMNAS,
    vector<double>(NFRAMES, 0.)));

    in Borland C++ Builder 6. I supposse an instance of this vector is
    created on the heap. Is that true? In such a case, should I destroy it
    when I don't need it anymore to release resources?. I tried to do it
    by mean the following sentence:

    Ez.~vector< vector< vector<double> > >();

    but I got the next exception

    Project ModoTM.exe raised exception class EAccessViolation with
    message 'Access violation at address 01194302 in module
    'BORLNDMM.DLL'. Read of address 00001DA0'. Process stopped. Use Step
    or Run to continue.

    where is the mistake with this approach?

    Thanks in advance ;-)
    joseantonio, Jan 13, 2005
    #1
    1. Advertising

  2. "joseantonio" <> schrieb im Newsbeitrag
    news:...
    > Hi all,
    >
    > I am novice in C++, (basically, novice using OOP). I am developing
    > an
    > application where I use a vector 3D defined as
    >
    > vector< vector< vector<double> > >
    > Ez(NFILAS, vector< vector<double> >(NCOLUMNAS,
    > vector<double>(NFRAMES, 0.)));
    >
    > in Borland C++ Builder 6. I supposse an instance of this vector is
    > created on the heap. Is that true? In such a case, should I destroy
    > it
    > when I don't need it anymore to release resources?. I tried to do it
    > by mean the following sentence:
    >
    > Ez.~vector< vector< vector<double> > >();


    the object calls the destructor when it get's out of scope:

    void foo()
    {
    vector<vector<vector<double> > > v3;
    // can use it here
    } // ~ will be called here

    You never must call it. If you allocate something with 'new', the
    corresponding 'delete' will call it before freeing memory.

    HTH,
    Gernot
    Gernot Frisch, Jan 13, 2005
    #2
    1. Advertising

  3. joseantonio

    Rolf Magnus Guest

    joseantonio wrote:

    > Hi all,
    >
    > I am novice in C++, (basically, novice using OOP). I am developing an
    > application where I use a vector 3D defined as
    >
    > vector< vector< vector<double> > >
    > Ez(NFILAS, vector< vector<double> >(NCOLUMNAS,
    > vector<double>(NFRAMES, 0.)));
    >
    > in Borland C++ Builder 6. I supposse an instance of this vector is
    > created on the heap. Is that true? In such a case, should I destroy it
    > when I don't need it anymore to release resources?. I tried to do it
    > by mean the following sentence:
    >
    > Ez.~vector< vector< vector<double> > >();
    >
    > but I got the next exception
    >
    > Project ModoTM.exe raised exception class EAccessViolation with
    > message 'Access violation at address 01194302 in module
    > 'BORLNDMM.DLL'. Read of address 00001DA0'. Process stopped. Use Step
    > or Run to continue.
    >
    > where is the mistake with this approach?


    It doesn't matter whether it's vector or any other type. If you define a
    local variable, it get automatically destroyed when it goes out of scope.
    Eplicit destructor calls are only very rarely needed.


    >
    > Thanks in advance ;-)
    Rolf Magnus, Jan 13, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sandhase
    Replies:
    1
    Views:
    364
    sandhase
    Nov 10, 2003
  2. pmatos
    Replies:
    6
    Views:
    23,721
  3. Ook
    Replies:
    2
    Views:
    312
  4. Replies:
    8
    Views:
    1,887
    Csaba
    Feb 18, 2006
  5. Replies:
    1
    Views:
    114
    Bob Barrows [MVP]
    Jul 31, 2008
Loading...

Share This Page