| 1198 | |
| 1199 | #if !defined(TORQUE_DISABLE_MEMORY_MANAGER) |
| 1200 | static Header *allocMemPage(dsize_t pageSize) |
| 1201 | { |
| 1202 | pageSize += sizeof(Header); |
| 1203 | if(pageSize < MinPageSize) |
| 1204 | pageSize = MinPageSize; |
| 1205 | PageRecord *base = allocPage(pageSize); |
| 1206 | |
| 1207 | Header* rec = (Header*)base->basePtr; |
| 1208 | base->headerList = rec; |
| 1209 | |
| 1210 | rec->size = pageSize - sizeof(Header); |
| 1211 | rec->next = NULL; |
| 1212 | rec->prev = NULL; |
| 1213 | rec->flags = 0; |
| 1214 | #ifdef TORQUE_DEBUG_GUARD |
| 1215 | setGuard(rec, true); |
| 1216 | #endif |
| 1217 | |
| 1218 | #ifdef LOG_PAGE_ALLOCS |
| 1219 | gPageBytesAllocated += pageSize; |
| 1220 | // total bytes allocated so far will be 0 when TORQUE_DEBUG_GUARD is disabled, so convert that into more meaningful string |
| 1221 | const U32 StrSize = 256; |
| 1222 | char strBytesAllocated[StrSize]; |
| 1223 | if (gBytesAllocated > 0) |
| 1224 | dSprintf(strBytesAllocated, sizeof(strBytesAllocated), "%i", gBytesAllocated); |
| 1225 | else |
| 1226 | dStrncpy(strBytesAllocated,"unknown - enable TORQUE_DEBUG_GUARD", StrSize); |
| 1227 | |
| 1228 | #ifndef TORQUE_MULTITHREAD // May deadlock. |
| 1229 | // NOTE: This code may be called within Con::_printf, and if that is the case |
| 1230 | // this will infinitly recurse. This is the reason for the code in Con::_printf |
| 1231 | // that sets Con::active to false. -patw |
| 1232 | if (Con::isActive()) |
| 1233 | Con::errorf("PlatformMemory: allocating new page, total bytes allocated so far: %s (total bytes in all pages=%i)",strBytesAllocated,gPageBytesAllocated); |
| 1234 | #endif |
| 1235 | #endif |
| 1236 | return rec; |
| 1237 | } |
| 1238 | #endif |
| 1239 | |
| 1240 | #if !defined(TORQUE_DISABLE_MEMORY_MANAGER) |