Skip to content

Commit

Permalink
Fix heap size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
gamemasterplc authored and rasky committed Oct 15, 2024
1 parent b300b56 commit 4e889f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/n64sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ void die(void)

void sys_get_heap_stats(heap_stats_t *stats)
{
extern char *__heap_end;
extern char *__heap_top;
extern int __heap_total_size;
struct mallinfo m = mallinfo();

stats->total = (int)((unsigned long)__heap_top - (unsigned long)__heap_end);
stats->total = __heap_total_size;
stats->used = m.uordblks;
}

Expand Down
4 changes: 4 additions & 0 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
*/
#define STACK_SIZE 0x10000


/** Total Size of the heap */
int __heap_total_size = 0;
/** End of the heap */
char *__heap_end = 0;
/** Top of the heap */
Expand Down Expand Up @@ -1024,6 +1027,7 @@ void *sbrk( int incr )
{
__heap_end = (char*)HEAP_START_ADDR;
__heap_top = (char*)KSEG0_START_ADDR + get_memory_size() - STACK_SIZE;
__heap_total_size = (int)((unsigned long)__heap_top - (unsigned long)__heap_end);
}

prev_heap_end = __heap_end;
Expand Down

0 comments on commit 4e889f0

Please sign in to comment.