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 > Memory map

#43201 - enliteneer - Fri May 20, 2005 6:57 am

Just ran across a very nice overview of programming the GBA
( http://members.iinet.net.au/~freeaxs/gbacomp/ ) that Im sure everyone here is familiar with.

However, Ive got a question regarding the memory map. Is it true that the linker will always put variables into external ram unless you specifically direct it to put it in internal ram? What about at runtime if you use malloc, where will that memory come from?

My program needs to save a unknown amount of data coming in from the serial, any suggestions on how best to allocate memory for this???

#43209 - Cearn - Fri May 20, 2005 11:14 am

enliteneer wrote:
Is it true that the linker will always put variables into external ram unless you specifically direct it to put it in internal ram?

It's the other way around: global variables go into IWRAM, unless explicitly told otherwise.

enliteneer wrote:
What about at runtime if you use malloc, where will that memory come from?

*tests* Apparently, devkitARM's malloc uses EWRAM.

enliteneer wrote:
My program needs to save a unknown amount of data coming in from the serial, any suggestions on how best to allocate memory for this???

Just how unknown is the amount of data? If there is a definite (and reasonable) upper limit, you might as well use a static array.

#43227 - tepples - Fri May 20, 2005 5:04 pm

Interrupt service routines should not see dynamically allocated memory because of the danger of race conditions: if they're called while malloc() or free() is running, disaster may ensue. To handle data coming from the serial port, you should statically allocate enough RAM for about 50ms (3 frames) of ring buffer, and have the main game loop copy from there to a larger buffer.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43304 - enliteneer - Sat May 21, 2005 8:27 pm

The serial traffic will range from a few bytes (commands, etc) to as much as a few MBs (data). Fortunately, it doesnt need to buffer all of the data, as it will be processing it as it comes in.

By the way, anyone tried the MBV2 cable?

Originally, I just soldered 3 wires to the di/do/gnd of the link connector to a ttl/rs232 converter, but having wires stick out of the gba looks ugly. The MBV2 cable comes with the connector, but doesnt seem to be designed to work as just a general purpose uart.