MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / region_create

Function region_create

TheForceEngine/TFE_Memory/memoryRegion.cpp:140–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 4

region_testFunction · 0.85
texturepacker_initFunction · 0.85
lsystem_initFunction · 0.85
game_initFunction · 0.85

Calls 3

logWriteFunction · 0.85
allocateNewBlockFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected