Someone knows how can I destroy a 3D vector?

J

joseantonio

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 ;-)
 
G

Gernot Frisch

joseantonio said:
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
 
R

Rolf Magnus

joseantonio said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top