void CGFreeMem() { static char cRAMBuff[16]; int iFree = Z_FreeMemory(); CGDAppendNum0_999("Free:",iFree,0,cRAMBuff); plyr->message = cRAMBuff; }
void Z_PrintStatus(void) { size_t allocated = Z_AllocatedMemory(); size_t wasted = Z_FreeMemory(); App_Log(DE2_LOG_DEBUG, "Memory zone status: %u volumes, %u bytes allocated, %u bytes free (%f%% in use)", Z_VolumeCount(), (uint)allocated, (uint)wasted, (float)allocated/(float)(allocated+wasted)*100.f); }
static void D_PrintDevStats(void) { int verts = dsvertices; int tris = dspolygons; ST_DrawMessage(0, 0, ARGB16(31, 0, 31, 0), "Memory: %ikb\n", Z_FreeMemory() >> 10); ST_DrawMessage(0, 8, ARGB16(31, 0, 31, 0), "Static: %ikb\n", Z_TagUsage(PU_STATIC) >> 10); ST_DrawMessage(0, 16, ARGB16(31, 0, 31, 0), "Cache: %ikb\n", Z_TagUsage(PU_CACHE) >> 10); ST_DrawMessage(0, 24, ARGB16(31, 0, 31, 0), "Audio: %ikb\n", Z_TagUsage(PU_AUDIO) >> 10); ST_DrawMessage(0, 32, ARGB16(31, 0, 31, 0), "DMA: %ikb\n", gfxdmasize >> 10); ST_DrawMessage(0, 40, ARGB16(31, 0, 31, 0), "Vram: %ikb\n", Z_FreeVMemory(vramzone) >> 10); ST_DrawMessage(0, 48, ARGB16(31, 0, 31, 0), "Vertex: %i\n", verts); ST_DrawMessage(0, 56, ARGB16(31, 0, 31, 0), "Tris: %i\n", tris); ST_DrawMessage(0, 64, ARGB16(31, 0, 31, 0), "Bsp: %ims\n", bsptic); ST_DrawMessage(0, 72, ARGB16(31, 0, 31, 0), "Draw: %ims\n", rendertic); ST_DrawMessage(0, 80, ARGB16(31, 0, 31, 0), "Game: %ims\n", ptic); }
void* Z_Malloc(int size, int tag, void* user) { int extra; memblock_t* start; memblock_t* rover; memblock_t* newblock; memblock_t* base; size = (size + 3) & ~3; // scan through the block list, // looking for the first free block // of sufficient size, // throwing out any purgable blocks along the way. // account for size of block header size += sizeof(memblock_t); // if there is a free block behind the rover, // back up over them base = mainzone->rover; if (!base->prev->user) { base = base->prev; } rover = base; start = base->prev; do { if (rover == start) { // scanned all the way around the list char ermac[256]; sprintf(ermac, "Z_Malloc: failed on allocation of %i bytes", size); I_Error(ermac); } if (rover->user) { if (rover->tag < PU_PURGELEVEL) { // hit a block that can't be purged, // so move base past it base = rover = rover->next; } else { // free the rover block (adding the size to base) // the rover can be the base block base = base->prev; Z_Free ((byte *)rover+sizeof(memblock_t)); base = base->next; rover = base->next; } } else { rover = rover->next; } } while (base->user || base->size < size); // found a block big enough extra = base->size - size; if (extra > MINFRAGMENT) { // there will be a free fragment after the allocated block newblock = (memblock_t *) ((byte *)base + size ); newblock->size = extra; // NULL indicates free block. newblock->user = NULL; newblock->tag = 0; newblock->prev = base; newblock->next = base->next; newblock->next->prev = newblock; base->next = newblock; base->size = size; } if (user) { // mark as an in use block base->user = user; *(void **)user = (void *) ((byte *)base + sizeof(memblock_t)); } else { if (tag >= PU_PURGELEVEL) { I_Error("Z_Malloc: an owner is required for purgable blocks"); } // mark as in use, but unowned base->user = (void *)2; } base->tag = tag; // next allocation will start looking here mainzone->rover = base->next; base->id = ZONEID; int current_used = I_GetHeapSize() - Z_FreeMemory(); if(maximum_zone_used < current_used) { maximum_zone_used = current_used; } return (void *) ((byte *)base + sizeof(memblock_t)); }