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 > How much memory in IWRAM?

#175942 - brave_orakio - Mon Mar 07, 2011 3:08 am

Hi guys, its me again! You guys must be getting sick of me asking so many questions! Heh

Generally, how do I compute how much memory a function in IWRAM will take?

I was messing around with my stuff one time when I tried putting some functions in IWRAM for testing. When I tried to run it, the emulator froze! So I removed some of the other stuff not required for IWRAM and tried it again then it worked just fine.

This got me thinking, how do I know how much memory a function takes? By the way I use the filename.iwram.c format if it makes answering this question any easier.
_________________
help me

#175945 - Ruben - Mon Mar 07, 2011 2:05 pm

Usually, you'll get a warning when you go past the limit of IWRAM (it's 32kB).
I'm not sure about libgba, but the stack usually goes in IWRAM, so you'll want to leave about 256 bytes from the last function for the user stack.

That said, you can look at how your memory is mapped by using nm (arm-eabi-nm -S -n YourElf.elf > Map.txt)

This should give you function/data/etc sizes and start addresses (the size only appears if it's compiled code or if you use the .size directive in assembler files).
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#175948 - kusma - Mon Mar 07, 2011 7:53 pm

One problem is that the stack is also located in IWRAM (unless you're using a custom linker-script, which I strongly discourage), and it is practically impossible to figure out for sure how much stack a non-trivial application requires. So when you're close to the limit you don't get linker-errors, you get "random" crashes because function calls starts writing to nonexistent memory.

#175951 - brave_orakio - Tue Mar 08, 2011 2:03 am

Hey thanks Ruben! I'll try that at home later tonight.

@kusma - Yes that is probably what happened to me! I probably declared too many arrays for the objects in my game cause I'm avoiding dynamic allocation for now. Between that and the local variables, that's what probably caused the crash. So I removed some of the other stuff from IWRAM and I also started making my structs smaller so its memory requirement is smaller.
_________________
help me

#175952 - Ruben - Tue Mar 08, 2011 8:23 am

If you need non-constant arrays, why don't use you EWRAM? (EWRAM_DATA for initialized data, EWRAM_BSS for uninitialized data)
It may be slower, but you have 256kB of it ;D

... Unless you use multiboot, in which case you only have (256-x)kB, where x is the executable size.
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#175954 - brave_orakio - Wed Mar 09, 2011 1:51 am

I am considering doing that as well. But since I'm just prototyping and testing if my ideas work, I haven't gotten around to moving them to EWRAM yet.
_________________
help me