void Com_InitHunkMemory( void ) {
cvar_t *cv;
int nMinAlloc;
char *pMsg = NULL;
if (FS_LoadStack() != 0) {
Com_Error( ERR_FATAL, "Hunk initialization failed. File system load stack not zero");
}
cv = Cvar_Get( "com_hunkMegs", DEF_COMHUNKMEGS_S, CVAR_LATCH | CVAR_ARCHIVE );
Cvar_SetDescription(cv, "The size of the hunk memory segment");
#ifdef __ORBIS__
if ( cv->integer < MIN_COMHUNKMEGS ) {
Cvar_Set( "com_hunkMegs", DEF_COMHUNKMEGS_S );
cv = Cvar_Get( "com_hunkMegs", DEF_COMHUNKMEGS_S, CVAR_LATCH | CVAR_ARCHIVE );
}
#endif
if (com_dedicated && com_dedicated->integer) {
nMinAlloc = MIN_DEDICATED_COMHUNKMEGS;
pMsg = "Minimum com_hunkMegs for a dedicated server is %i, allocating %i megs.\n";
} else {
nMinAlloc = MIN_COMHUNKMEGS;
pMsg = "Minimum com_hunkMegs is %i, allocating %i megs.\n";
}
if ( cv->integer < nMinAlloc ) {
s_hunkTotal = 1024 * 1024 * nMinAlloc;
Com_Printf(pMsg, nMinAlloc, s_hunkTotal / (1024 * 1024));
} else {
s_hunkTotal = cv->integer * 1024 * 1024;
}
#ifdef __ORBIS__
{
void *ptr;
// 32-byte alignment, valid pointer for free()
if (posix_memalign(&ptr, 32, s_hunkTotal) != 0) {
Com_Error( ERR_FATAL, "Hunk data failed to allocate %i megs", s_hunkTotal / (1024*1024) );
}
s_hunkData = (byte *)ptr;
}
#else
s_hunkData = calloc( s_hunkTotal + 31, 1 );
if ( !s_hunkData ) {
Com_Error( ERR_FATAL, "Hunk data failed to allocate %i megs", s_hunkTotal / (1024*1024) );
}
// cacheline align
s_hunkData = (byte *) ( ( (intptr_t)s_hunkData + 31 ) & ~31 );
#endif
Hunk_Clear();
Cmd_AddCommand( "meminfo", Com_Meminfo_f );
#ifdef ZONE_DEBUG
Cmd_AddCommand( "zonelog", Z_LogHeap );
#endif
#ifdef HUNK_DEBUG
Cmd_AddCommand( "hunklog", Hunk_Log );
Cmd_AddCommand( "hunksmalllog", Hunk_SmallLog );
#endif
}