gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Finding out how full RAM is

#27038 - ScottLininger - Sat Oct 02, 2004 12:33 am

Can anyone tell me a way to tell how much RAM you've used? I know I saw a post on this before, but I couldn't find it...

Visual Boy Advance is the current emulator I use. Its memory viewer is less than helpful... since it seems that all of ram has unrecognizable data in it, unless I'm just reading it wrong.

Thanks!

Scott

#27040 - ampz - Sat Oct 02, 2004 12:51 am

You wanna check this live on the hardware?
There are a couple of ways I guess...
You could write a small asm loop in the c startup code that fills RAM with a known integer value (like 0x12345678 or something). Run your program for a while, and then chek how much of the RAM has been rewritten.

If you want to know exatly how much RAM you use at a specific point, then just read the stack pointer. Of course, you must also take the heap into account if you use it.

#27044 - tepples - Sat Oct 02, 2004 1:05 am

nm -n myprogram.elf

then look at how closely the addresses approach 0x02400000 and 0x03007c00 (the top of two GBA RAM areas)
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#27054 - sajiimori - Sat Oct 02, 2004 4:51 am

It totally depends on how your memory is being allocated. 'nm' can tell you all about static allocations, and the stack pointer can be checked pretty easily at runtime, but finding out about heap usage isn't possible with the standard C library so you have to either track it yourself or use your own allocator from the start.

#27055 - MumblyJoe - Sat Oct 02, 2004 6:45 am

You could write your own malloc/free or operator new/delete and have them keep count, kinda. It wouldn't be accurate unless you also knew how much room any functions put in ram are using for code and how much stack is bieng used, but I'm sure somebody here knows more than me about that sort of thing and can write something.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#27061 - DiscoStew - Sat Oct 02, 2004 9:17 am

Is there a way when using 'nm' to page through all the static allocations and functions, like how in DOS you could go page by page when looking through directories/files? The last time I tried a normal 'nm' with an ELF file, the list went clear past anything shown in RAM, and went past most things in ROM. This is because I've got a lot of stuff in it.
_________________
DS - It's all about DiscoStew

#27065 - MumblyJoe - Sat Oct 02, 2004 9:40 am

put "| more" (without the quotes) after your nm thing.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#27069 - poslundc - Sat Oct 02, 2004 2:38 pm

Or redirect it into a file ("> myfile") and use a text editor to browse it freely.

Dan.