#6655 - Naaga - Sun Jun 01, 2003 3:48 am
I just started with GBA development, and I think I need info on memory management. It sounds like most people allocate memory directly by address, which I'm not used to doing, since it's a big no-no in PC programming. So where can I get info on the different areas of memory (IWRAM, VRAM, ROM...), what their address ranges are, and what to use them for? Am I even on the right track?
#6657 - niltsair - Sun Jun 01, 2003 5:55 am
There's are good technical documents out there, such as this one :
http://www.cs.rit.edu/~tjh8300/CowBite/CowBiteSpec.htm
Basicly you have :
IWRAM : Internal Work Ram. 32k. Fast, used by default when declaring variables. Used by the stack.
EWRAM : External Work Ram 256k, slower of access,.
And all other display related memory, such as Palette, Video, Object(sprite), Object's palette...
#6658 - Naaga - Sun Jun 01, 2003 6:17 am
Thanks for the link. Am I right about being able to read and write to and from memory freely by address?
#6659 - niltsair - Sun Jun 01, 2003 7:12 am
You're better off using variables.
You don't know what's in IWRAM, because it's used both for call stack and declared variables. I think EWRAM coudl be used the way you said, but again for clarity sake, you're better off using variable(that's a personal opinion)
Where we use address directly, it's for video memory, and this is because we know what's where. Exemple, in mode 3, each pixels takes 2Byte, so we know that at address 0x06000000+440,reside the pixel 60X 1Y.
X=(440/2)%160
Y=(440/2)/160
Same apply for palette entries, Sprites.
#6684 - Naaga - Sun Jun 01, 2003 10:33 pm
Maybe I need to explain myself better. The document you linked shows a bunch of different address ranges and what they're used for, like ROM, which starts at 0x08000000. I assume ROM is used for data storage. Would I be able to write an object that will allocate space in ROM for certain things?
For instance, maybe I start with a char* that stores the first address, 0x08000000. Maybe I want to store a bunch of 16x16 bitmaps first. So I tell the object the amount of memory I want for a certain thing, it puts the data starting at 0x08000000, moves the pointer immediately after the newly used memory, and returns a pointer to the new data (basically a stack.) Can I access and manage memory at this level, or am I better off using malloc or something else?
#6685 - niltsair - Sun Jun 01, 2003 11:00 pm
Rom is read only, so you couldn't do that. This is where your program's code resides.
If you want to do what you said without problem, do it in EWRAM (given you never declare code/variable to reside there) This memory is never used untill you specificly tell something to use it.
Another solution (given you don't want to use a too big dynamic area) would be to declare a global array stored in IWRAM. You then manage yourself the content of the array. I'm not certain how much space you could reserve safely. IWRAM only has 32k of space and, depending on how much global variables you're using and the biggest memory amount used inside functions, i'd say 16k would be ok if no other big array is used.
Why IWRAM->Faster.
Why declare an Array->To be sure you never overwrite important data in IWRAM(stack, other variables).
If you don't use EWRAM for anythign else, you don't have to declare an array like in IWRAM.
Does that help you?
Last edited by niltsair on Sun Jun 01, 2003 11:55 pm; edited 1 time in total
#6688 - Naaga - Sun Jun 01, 2003 11:17 pm
OK, I think I get it now. Thanks for the help.