Hello all,
I've been in the programming world for just few years, and I've been using Java for the most part of it.
I started studying c++ by my own just recently, and I still don't feel comfortable with deleting pointers.
So I would appreciate if someone could review my code and tell me if I'm doing the right things.
First of all, my constructor goes like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
template <typename T>
Array3<T>::Array3(const sf::Vector3s& size) :
m_size(size)
{
m_array = new T**[m_size.x];
for (int i = 0; i < m_size.x; i++)
{
m_array[i] = new T*[m_size.y];
for (int j = 0; j < m_size.y; j++)
{
m_array[i][j] = new T[m_size.z];
}
}
}
|
Just for your information, sf::Vector3<T> is a simple class from SFML containing T x, T y, T z.
And finally, my destructor goes like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
template <typename T>
Array3<T>::~Array3()
{
for (int i = 0; i < m_size.x; i++)
{
for (int j = 0; j < m_size.y; j++)
{
delete[] m_array[i][j];
}
delete[] m_array[i];
}
delete[] m_array;
}
|
According the following code, is there any possible memory leak?
Anything wrong, inefficient, something about my code?
Thank you in advance.
P.S. Is there anything in STL that already implements what I did here? (I don't mean like std::vector<std::vector<std::vector<T>>>)