about delete[]

H

hyena

I have following code:


void free(double** a){

for(int i =0; i< 100;i++){
delete[] *(a+i);
}
}

double** t;
t= new double*[100];
for(int i =0; i< 100;i++){
*(t+i) = new double[100];
}

the idea is to create two dimensional array and use free() to free up the
memory, will this work?
 
G

Gianni Mariani

hyena said:
I have following code:


void free(double** a){

for(int i =0; i< 100;i++){
delete[] *(a+i);
}

delete [] a; // don't forget to delete the primary array too.
}

double** t;
t= new double*[100];
for(int i =0; i< 100;i++){
*(t+i) = new double[100];
}

the idea is to create two dimensional array and use free() to free up the
memory, will this work?

Yes, but it's best to use a matrix class. There are plenty of posts and
free libraries that show the matrix class.
 

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

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top