kouky wrote:
Questyion: is there a way to know how much RAM is still available while the software is running?
something simple like: u64 freeRAM= memoryAvailable(); ???
I had a look inside malloc.c in PS2SDK and it does not keep track of how much memory has been allocated and freeed, so you need to keep track of this yourself.
Your program (ELF) along with the stack will most likely not take up more than 1 MB of memory and the EE kernel sits in the first 1 MB of memory, so I think it's safe to assume that you have 32 - 2 = 30 MB of memory which you can malloc.
I made a small HeapSize() function which tells you exactly how much memory you can avaliable before the first malloc of your program, eg. size of the heap.
Code: Select all
#include <tamtypes.h>
#include <kernel.h>
#include <stdio.h>
extern void * _end;
u32 HeapSize()
{
u32 endofprogram = (u32)&_end;
u32 endofheap = (u32)EndOfHeap();
return endofheap - endofprogram;
}
void PrintSize(FILE *fd, u32 size)
{
u32 mb = size / (1024*1024);
u32 kb = (size - (mb*1024*1024)) / 1024;
u32 b = size - (mb*1024*1024) - (kb*1024);
fprintf(fd, "%i MB %i KB %i B\n", mb, kb, b);
}
int main(int argc, char *argv[])
{
printf("HeapSize: ");
PrintSize(stdout, HeapSize());
return 0;
}
When running this program you get the following result.