extern "C" void * MYCDECL CUSTOM_REALLOC (void * ptr, size_t sz) { if (ptr == NULL) { ptr = internalMalloc (sz); return ptr; } if (sz == 0) { CUSTOM_FREE (ptr); return NULL; } size_t objSize = CUSTOM_GETSIZE (ptr); void * buf = internalMalloc(sz); if (buf != NULL) { if (objSize == CUSTOM_GETSIZE(buf)) { // The objects are the same actual size. // Free the new object and return the original. CUSTOM_FREE (buf); return ptr; } // Copy the contents of the original object // up to the size of the new block. size_t minSize = (objSize < sz) ? objSize : sz; memcpy (buf, ptr, minSize); } // Free the old block. CUSTOM_FREE (ptr); // Return a pointer to the new one. return buf; }
extern "C" void * MYCDECL CUSTOM_REALLOC (void * ptr, size_t sz) { if (ptr == NULL) { ptr = __malloc_impl(sz); return ptr; } if (sz == 0) { __free_impl(ptr); return NULL; } size_t objSize = CUSTOM_GETSIZE (ptr); void * buf = __malloc_impl((size_t) (sz)); if (buf != NULL) { // Copy the contents of the original object // up to the size of the new block. size_t minSize = (objSize < sz) ? objSize : sz; memcpy (buf, ptr, minSize); } // Free the old block. __free_impl(ptr); // Return a pointer to the new one. return buf; }
size_t mysize (malloc_zone_t * zone, const void * ptr) { size_t sz; if (zone == theZone) { sz = CUSTOM_GETSIZE(ptr); } else { sz = originalSize (zone, ptr); } return sz; }