Display used RAM?
Display used RAM?
Is there a function to display the used ram in libnds?
-
- Site Admin
- Posts: 2052
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: Display used RAM?
Short answer, no.
Longer answer :-
There is code in newlib which can help determine how much RAM is left to allocate and some internal variables used by the code I added to newlib for allocation. This should help a bit but mostly there's very little need to check this directly and this method won't necessarily tell you if sufficient RAM is left to make an allocation. The memory can become fragmented if you're not careful and the largest block available may not be the total RAM left.
Longer answer :-
There is code in newlib which can help determine how much RAM is left to allocate and some internal variables used by the code I added to newlib for allocation. This should help a bit but mostly there's very little need to check this directly and this method won't necessarily tell you if sufficient RAM is left to make an allocation. The memory can become fragmented if you're not careful and the largest block available may not be the total RAM left.
Code: Select all
#include <malloc.h> // for mallinfo()
#include <unistd.h> // for sbrk()
extern u8 *fake_heap_end; // current heap start
extern u8 *fake_heap_start; // current heap end
u8* getHeapStart() {
return fake_heap_start;
}
u8* getHeapEnd() {
return (u8*)sbrk(0);
}
u8* getHeapLimit() {
return fake_heap_end;
}
int getMemUsed() { // returns the amount of used memory in bytes
struct mallinfo mi = mallinfo();
return mi.uordblks;
}
int getMemFree() { // returns the amount of free memory in bytes
struct mallinfo mi = mallinfo();
return mi.fordblks + (getHeapLimit() - getHeapEnd());
}
Who is online
Users browsing this forum: No registered users and 3 guests