I am not sure what are the effects of using realloc() with new[] even when you take pains to copy back, so I shall not comment on that.

However, I note that you did not match the new[] with delete[] (but with delete, which is incorrect), and that if the new size is less than the old size, you might as well return immediately. The realloc() does not seem useful in the first place: if you have a pointer to a temporary array, you might as well create that array with the new size, and then copy over the elements, then assign the pointer to the original (or in this case, return the pointer to the "temporary" array). At the moment you are copying back and forth, which is a waste of time.

You might want to read the "Allocating Arrays Using Placement new" article, especially the "Performance Tuning" section. Also, note that this is dotz02x's thread, so perhaps you would like to give dotz02x a chance to post an attempted solution.