// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>

using namespace std;

void redim1(char *p,int oldsiz,int newsiz) {
   char *pp = new char[newsiz];
   cout << "new address = " << (int)pp << " length = " << newsiz << endl;
   memcpy(pp,p,oldsiz);
   char *ppp = p;
   p = pp;
   delete[] ppp;
   cout << "delete address = " << (int)ppp << endl;
   return;
}

void redim2(char **p,int oldsiz,int newsiz) {
   char *pp = new char[newsiz];
   cout << "new address = " << (int)pp << " length = " << newsiz << endl;
   memcpy(pp,*p,oldsiz);
   char *ppp = *p;
   *p = pp;
   delete[] ppp;
   cout << "delete address = " << (int)ppp << endl;
   return;
}

int main()
{
   char *p1 = new char[100];
   cout << "new address = " << (int)p1 << " length = 100" << endl;
   redim1(p1,100,200);
   cout << "redim address = " << (int)p1 << " length = 200" << endl;
   cout << "----------" << endl;
   char *p2 = new char[100];
   cout << "new address = " << (int)p2 << " length = 100" << endl;
   redim2(&p2,100,200);
   cout << "redim address = " << (int)p2 << " length = 200" << endl;
}
