[QUESTION] DMA Deletion

Hello community. I was writing a simple times table project that creates a table object that gets created and then deleted with every iteration within a for loop.

Skim the code below.

1
2
3
4
5
6
7
8
9
#define uint unisgned int

TimesTable::~TimesTable()
{
    for(uint i = 0; i < m_row; i++)
        delete table[i];
        
    delete table;
}


Was delete table[i] proper? I've seen people use delete [] table[i] as well. Are these the same thing?
You must use delete[] when you use new[]. In other words, if you do this:

1
2
SomeType *arrary = new SomeType[4];
SomeType *p  = new SomeType;

then you must delete them with
1
2
delete[] array;
delete p;

By using delete[] on array, you guarantee that SomeType's destructor will get called on all 4 items in the array.

So to answer your question, it depends on what table[i] points to. If it points to a single item then use delete. If it points to an array then use delete[]
Amazing; thank you for the clarification.
Topic archived. No new replies allowed.