MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Cvar_Defrag

Function Cvar_Defrag

code/qcommon/cvar.cpp:1407–1446  ·  view source on GitHub ↗

Turns many small allocation blocks into one big one.

Source from the content-addressed store, hash-verified

1405
1406//Turns many small allocation blocks into one big one.
1407void Cvar_Defrag(void)
1408{
1409 cvar_t *var;
1410 int totalMem = 0;
1411 int nextMemPoolSize;
1412
1413 for (var = cvar_vars; var; var = var->next)
1414 {
1415 if (var->name) {
1416 totalMem += strlen(var->name) + 1;
1417 }
1418 if (var->string) {
1419 totalMem += strlen(var->string) + 1;
1420 }
1421 if (var->resetString) {
1422 totalMem += strlen(var->resetString) + 1;
1423 }
1424 if (var->latchedString) {
1425 totalMem += strlen(var->latchedString) + 1;
1426 }
1427 }
1428
1429 char *mem = (char*)Z_Malloc(totalMem, TAG_SMALL, qfalse);
1430 nextMemPoolSize = totalMem;
1431 totalMem = 0;
1432
1433 for (var = cvar_vars; var; var = var->next)
1434 {
1435 Cvar_Realloc(&var->name, mem, totalMem);
1436 Cvar_Realloc(&var->string, mem, totalMem);
1437 Cvar_Realloc(&var->resetString, mem, totalMem);
1438 Cvar_Realloc(&var->latchedString, mem, totalMem);
1439 }
1440
1441 if(lastMemPool) {
1442 Z_Free(lastMemPool);
1443 }
1444 lastMemPool = mem;
1445 memPoolSize = nextMemPoolSize;
1446}
1447

Callers 1

SV_SpawnServerFunction · 0.50

Calls 3

Z_MallocFunction · 0.70
Cvar_ReallocFunction · 0.70
Z_FreeFunction · 0.70

Tested by

no test coverage detected