| 1036 | // --------------------------------------------------------------------------------------------------------------------------------- |
| 1037 | |
| 1038 | void *m_allocator(const char *sourceFile, const unsigned int sourceLine, const char *sourceFunc, const unsigned int allocationType, const size_t reportedSize) |
| 1039 | { |
| 1040 | try |
| 1041 | { |
| 1042 | #ifdef TEST_MEMORY_MANAGER |
| 1043 | log("[D] ENTER: m_allocator()"); |
| 1044 | #endif |
| 1045 | |
| 1046 | // Increase our allocation count |
| 1047 | |
| 1048 | currentAllocationCount++; |
| 1049 | |
| 1050 | // Log the request |
| 1051 | |
| 1052 | if (alwaysLogAll) log("[+] %05d %8s of size 0x%08X(%08d) by %s", currentAllocationCount, allocationTypes[allocationType], reportedSize, reportedSize, ownerString(sourceFile, sourceLine, sourceFunc)); |
| 1053 | |
| 1054 | // If you hit this assert, you requested a breakpoint on a specific allocation count |
| 1055 | m_assert(currentAllocationCount != breakOnAllocationCount); |
| 1056 | |
| 1057 | // If necessary, grow the reservoir of unused allocation units |
| 1058 | |
| 1059 | if (!reservoir) |
| 1060 | { |
| 1061 | // Allocate 256 reservoir elements |
| 1062 | |
| 1063 | reservoir = (sAllocUnit *) malloc(sizeof(sAllocUnit) * 256); |
| 1064 | |
| 1065 | // If you hit this assert, then the memory manager failed to allocate internal memory for tracking the |
| 1066 | // allocations |
| 1067 | m_assert(reservoir != NULL); |
| 1068 | |
| 1069 | // Danger Will Robinson! |
| 1070 | |
| 1071 | if (reservoir == NULL) throw "Unable to allocate RAM for internal memory tracking data"; |
| 1072 | |
| 1073 | // Build a linked-list of the elements in our reservoir |
| 1074 | |
| 1075 | memset(reservoir, 0, sizeof(sAllocUnit) * 256); |
| 1076 | for (unsigned int i = 0; i < 256 - 1; i++) |
| 1077 | { |
| 1078 | reservoir[i].next = &reservoir[i+1]; |
| 1079 | } |
| 1080 | |
| 1081 | // Add this address to our reservoirBuffer so we can free it later |
| 1082 | |
| 1083 | sAllocUnit **temp = (sAllocUnit **) realloc(reservoirBuffer, (reservoirBufferSize + 1) * sizeof(sAllocUnit *)); |
| 1084 | m_assert(temp); |
| 1085 | if (temp) |
| 1086 | { |
| 1087 | reservoirBuffer = temp; |
| 1088 | reservoirBuffer[reservoirBufferSize++] = reservoir; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | // Logical flow says this should never happen... |
| 1093 | m_assert(reservoir != NULL); |
| 1094 | |
| 1095 | // Grab a new allocaton unit from the front of the reservoir |
no test coverage detected