void _vm_free( void *ptr ) #endif { if (!ptr) { #ifndef NDEBUG mprintf(("Why are you trying to free a NULL pointer? [%s(%d)]\n", clean_filename(filename), line)); #else mprintf(("Why are you trying to free a NULL pointer?\n")); #endif return; } #ifndef NDEBUG _CrtMemBlockHeader* phd = pHdr(ptr); int nSize = phd->nDataSize; TotalRam -= nSize; if (Cmdline_show_mem_usage) unregister_malloc(filename, nSize, ptr); #endif _free_dbg(ptr, _NORMAL_BLOCK); }
void *_vm_realloc( void *ptr, int size, int quiet ) #endif { // if this is the first time it's used then we need to malloc it first if (ptr == NULL) return vm_malloc(size); void* ret_ptr = NULL; #ifndef NDEBUG // Unregistered the previous allocation _CrtMemBlockHeader* phd = pHdr(ptr); int nSize = phd->nDataSize; TotalRam -= nSize; if (Cmdline_show_mem_usage) unregister_malloc(filename, nSize, ptr); #endif ret_ptr = _realloc_dbg(ptr, size, _NORMAL_BLOCK, __FILE__, __LINE__); if (ret_ptr == NULL) { mprintf(("realloc failed!!!!!!!!!!!!!!!!!!!\n")); if (quiet && (size > 0) && (ptr != NULL)) { // realloc doesn't touch the original ptr in the case of failure so we could still use it return NULL; } Error(LOCATION, "Out of memory. Try closing down other applications, increasing your\n" "virtual memory size, or installing more physical RAM.\n"); } #ifndef NDEBUG TotalRam += size; // register this allocation if (Cmdline_show_mem_usage) register_malloc(size, filename, line, ret_ptr); #endif return ret_ptr; }
void _vm_free( void *ptr ) #endif { if ( !ptr ) { return; } #ifndef NDEBUG _CrtMemBlockHeader *phd = pHdr(ptr); int nSize = phd->nDataSize; TotalRam -= nSize; if(Cmdline_show_mem_usage) unregister_malloc(filename, nSize, ptr); #endif _free_dbg(ptr,_NORMAL_BLOCK); }