Fix I_GetFreeMem

This commit is contained in:
Jaime Ita Passos 2023-05-19 14:26:30 -03:00
parent 2c689bae52
commit 2f98cd3b97
5 changed files with 14 additions and 15 deletions

View file

@ -24,7 +24,7 @@ static INT64 start_time; // as microseconds since the epoch
// I should probably return how much memory is remaining
// for this process, considering Android's process memory limit.
UINT32 I_GetFreeMem(UINT32 *total)
size_t I_GetFreeMem(size_t *total)
{
// what the heck? sysinfo() is partially missing in bionic?
/* struct sysinfo si; */

View file

@ -8,7 +8,7 @@ UINT8 graphics_started = 0;
UINT8 keyboard_started = 0;
UINT32 I_GetFreeMem(UINT32 *total)
size_t I_GetFreeMem(UINT32 *total)
{
*total = 0;
return 0;

View file

@ -40,7 +40,7 @@ extern UINT8 keyboard_started;
\return free memory in the system
*/
UINT32 I_GetFreeMem(UINT32 *total);
size_t I_GetFreeMem(size_t *total);
/** \brief Returns precise time value for performance measurement. The precise
time should be a monotonically increasing counter, and will wrap.

View file

@ -2962,8 +2962,7 @@ static long get_entry(const char* name, const char* buf)
}
#endif
// quick fix for compil
UINT32 I_GetFreeMem(UINT32 *total)
size_t I_GetFreeMem(size_t *total)
{
#ifdef FREEBSD
struct vmmeter sum;
@ -3011,14 +3010,14 @@ UINT32 I_GetFreeMem(UINT32 *total)
info.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus( &info );
if (total)
*total = (UINT32)info.dwTotalPhys;
return (UINT32)info.dwAvailPhys;
*total = (size_t)info.dwTotalPhys;
return (size_t)info.dwAvailPhys;
#elif defined (__linux__)
/* Linux */
char buf[1024];
char *memTag;
UINT32 freeKBytes;
UINT32 totalKBytes;
size_t freeKBytes;
size_t totalKBytes;
INT32 n;
INT32 meminfo_fd = -1;
long Cached;
@ -3049,7 +3048,7 @@ UINT32 I_GetFreeMem(UINT32 *total)
}
memTag += sizeof (MEMTOTAL);
totalKBytes = atoi(memTag);
totalKBytes = (size_t)atoi(memTag);
if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL)
{

View file

@ -106,14 +106,14 @@ static void Command_Memdump_f(void);
*/
void Z_Init(void)
{
UINT32 total, memfree;
size_t total, memfree;
memset(&head, 0x00, sizeof(head));
head.next = head.prev = &head;
memfree = I_GetFreeMem(&total)>>20;
CONS_Printf("System memory: %uMB - Free: %uMB\n", total>>20, memfree);
CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(total>>20), sizeu2(memfree));
// Note: This allocates memory. Watch out.
COM_AddCommand("memfree", Command_Memfree_f, COM_LUA);
@ -791,7 +791,7 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag)
*/
static void Command_Memfree_f(void)
{
UINT32 freebytes, totalbytes;
size_t freebytes, totalbytes;
Z_CheckHeap(-1);
CONS_Printf("\x82%s", M_GetText("Memory Info\n"));
@ -824,8 +824,8 @@ static void Command_Memfree_f(void)
CONS_Printf("\x82%s", M_GetText("System Memory Info\n"));
freebytes = I_GetFreeMem(&totalbytes);
CONS_Printf(M_GetText(" Total physical memory: %7u KB\n"), totalbytes>>10);
CONS_Printf(M_GetText("Available physical memory: %7u KB\n"), freebytes>>10);
CONS_Printf(M_GetText(" Total physical memory: %s KB\n"), sizeu1(totalbytes>>10));
CONS_Printf(M_GetText("Available physical memory: %s KB\n"), sizeu1(freebytes>>10));
}
#ifdef ZDEBUG