| 138 | } |
| 139 | |
| 140 | MemoryRegion* region_create(const char* name, u64 blockSize, u64 maxSize) |
| 141 | { |
| 142 | assert(name); |
| 143 | if (!name || !blockSize) { return nullptr; } |
| 144 | if (blockSize > MAX_BLOCK_SIZE) |
| 145 | { |
| 146 | TFE_System::logWrite(LOG_ERROR, "MemoryRegion", "The block size for region '%s' of %u is too large, the maximum is %u.", name, blockSize, MAX_BLOCK_SIZE); |
| 147 | return nullptr; |
| 148 | } |
| 149 | |
| 150 | MemoryRegion* region = (MemoryRegion*)malloc(sizeof(MemoryRegion)); |
| 151 | if (!region) |
| 152 | { |
| 153 | TFE_System::logWrite(LOG_ERROR, "MemoryRegion", "Failed to allocate region '%s'.", name); |
| 154 | return nullptr; |
| 155 | } |
| 156 | |
| 157 | strcpy(region->name, name); |
| 158 | region->memBlocks = nullptr; |
| 159 | region->blockArrCapacity = 0; |
| 160 | region->blockCount = 0; |
| 161 | region->blockSize = blockSize; |
| 162 | region->maxBlocks = maxSize ? (maxSize + blockSize - 1) / blockSize : 0; |
| 163 | if (!allocateNewBlock(region)) |
| 164 | { |
| 165 | free(region); |
| 166 | TFE_System::logWrite(LOG_ERROR, "MemoryRegion", "Failed to memory block of size %u in region '%s'.", blockSize, name); |
| 167 | return nullptr; |
| 168 | } |
| 169 | VERIFY_MEMORY(); |
| 170 | |
| 171 | return region; |
| 172 | } |
| 173 | |
| 174 | void region_clear(MemoryRegion* region) |
| 175 | { |
no test coverage detected