title: Implementation of Realloc in C
body: <pre><code>int getmin(int a, int b)
  {
      return a&lt;b?a:b;
  }
  
  
  void *reallocation(void *ptr, size_t size) //size_t in bytes
  {
  
      void *newptr;
  
  
      int msize;
      msize = getsize(ptr);
  
      msize = getmin(msize, size);
  
          printf("msize = %d", msize);
  
      newptr = malloc(size);
      newptr = memcpy(newptr, ptr, msize);
      free(ptr);
  
  
      return newptr;
  
  }
  </code></pre>
  
  <p>I have implemented my own realloc, and in order to get the size of the allocated memory using malloc(however i know there isn't any method for this in c).</p>
  
  <p>My reallocation function is working fine on my system
  How do we get the size of the memory allocated by malloc().</p>
  
  <p>Also can we do inplace reallocation if the size of the previously allocated memory is greater than the new required?</p>