Does the following code will increase the allocated memory continuously as it is called repeatedly?
void ArrayStorage::merge(int low, int mid, int high)
{
int start = low;
int marker = low;
int secondStart = mid + 1;
temp = new string [high + 1];
//rest of the code
}
please share with me if you know about it…
Yes, because you’re not deleting the memory allocated by
new.The correct way is:
In C++, there’s no automatic memory management for dynamically allocated objects. Everytime you call
newormalloc(this method is usually for C), you allocate memory in dynamic storage, which you are responsible for freeing, viadeleteorfreerespectively. In your case, you allocate an array of sizehigh + 1which you need to free viadelete[].EDIT: As others have pointed out, maybe
std::vectoris better suited, but it depends on what you want to do. Look it up.