void *_vm_malloc( int size, int quiet ) #endif { void *ptr = NULL; ptr = _malloc_dbg(size, _NORMAL_BLOCK, __FILE__, __LINE__ ); if (ptr == NULL) { mprintf(( "Malloc failed!!!!!!!!!!!!!!!!!!!\n" )); if (quiet) { return NULL; } Error(LOCATION, "Malloc Failed!\n"); } #ifndef NDEBUG TotalRam += size; if(Cmdline_show_mem_usage) register_malloc(size, filename, line, ptr); #endif return ptr; }
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; }