Estimating ram and rom usage?
Moderator: Stef
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
Estimating ram and rom usage?
Hi,
Is there a way to estimate how much ram is being used by my game? Without having to count every variable in my code, that is.
Also, how can I tell how large my game rom is without the padding?
(as usual, I'm using SGDK)
Thanks!
DJCC
Is there a way to estimate how much ram is being used by my game? Without having to count every variable in my code, that is.
Also, how can I tell how large my game rom is without the padding?
(as usual, I'm using SGDK)
Thanks!
DJCC
-
- Very interested
- Posts: 2993
- Joined: Fri Aug 17, 2007 9:33 pm
First, set your makefile to generate a link map.
That will tell you the address and size of nearly everything. Second, make padding the rom a separate step with a different name than the binary. That way you can see what size the binary alone was.
Notice that making the elf file uses the flag that produces the link map. Then making the bin file makes the bin under a set name (temp.bin), and THEN pads it out to the desired size/multiple with the final name for the binary.
Code: Select all
LDFLAGS = -T $(LDSCRIPTSDIR)/mars.ld -Wl,-Map=output.map -nostdlib
Code: Select all
$(TARGET).bin: $(TARGET).elf
$(OBJC) -O binary $< temp.bin
$(DD) if=temp.bin of=$@ bs=4096K conv=sync
$(TARGET).elf: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(TARGET).elf
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
I think you already have memory managements methods in last version of SGDK so you should have
which returns the number if free bytes.
Basically you have 64 KB of memory so 64 KB - MEM_getFree() will return you the consumed memory
Code: Select all
u32 MEM_getFree()
Basically you have 64 KB of memory so 64 KB - MEM_getFree() will return you the consumed memory

-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
Stef wrote:I think you already have memory managements methods in last version of SGDK so you should havewhich returns the number if free bytes.Code: Select all
u32 MEM_getFree()
Basically you have 64 KB of memory so 64 KB - MEM_getFree() will return you the consumed memory
Heh! I didn't even know there was a memory manager.

-
- Very interested
- Posts: 2993
- Joined: Fri Aug 17, 2007 9:33 pm
It's a default part of EVERY *nix system out, and an installable part of cygwin and mingw. Ucon is great as well, but not a default thing, nor in any repo - you have to go get it from sourceforge. It's also a bit overkill for just padding a rom.KanedaFr wrote:It's why I use Ucon for padding
it tells you what is the size w/o padding
I'm not sure 'dd' is available on SGDK, no ?

One of the reasons I like dd is that it's very flexible... if the blocksize is smaller than the filesize, it makes it the next multiple of the blocksize. If it's bigger than the filesize, it pads it to the blocksize. So if you just want the rom to be a multiple of 8K, you just use bs=8K (or bs=8192).
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
One year later...
I've figured out how to generated a map file, but I'm having a bit of trouble interpreting it.
I posted Propeller's map file here: http://pastebin.com/R9yVam4J
Does line 264 (the one with __DYNAMIC = 0x0) indicate where the data stored in ROM starts? "playerSprite" is an import from genres, so I think so.
Does line 891 (first instance of .data) indicate where variables mapped to RAM starts? The .bss section seems related.
I've figured out how to generated a map file, but I'm having a bit of trouble interpreting it.
I posted Propeller's map file here: http://pastebin.com/R9yVam4J
Does line 264 (the one with __DYNAMIC = 0x0) indicate where the data stored in ROM starts? "playerSprite" is an import from genres, so I think so.
Does line 891 (first instance of .data) indicate where variables mapped to RAM starts? The .bss section seems related.
-
- Very interested
- Posts: 2993
- Joined: Fri Aug 17, 2007 9:33 pm
The linker script (ld) file sets things like where the rom and ram are. The map shows them like this (line 225):
Things like "__DYNAMIC = 0x0" are symbols set by the linker script and only make sense to the code that uses said symbols.
Starting at line 267 you get a list of the files that contributed to the .text section, at line 800 you get other sections that go into rom, at line 891 you get the .data section list, at line 975 you get the .bss section list, and at line 1086 you get all the common vars that wind up in the bss.
Line 1201 gives you this:
That is the end of ram usage by the program. Line 889 gives you this:
That is the end of rom usage by the program.
Code: Select all
Memory Configuration
Name Origin Length Attributes
rom 0x00000000 0x00a00000
ram 0x00ff0000 0x00010000
Starting at line 267 you get a list of the files that contributed to the .text section, at line 800 you get other sections that go into rom, at line 891 you get the .data section list, at line 975 you get the .bss section list, and at line 1086 you get all the common vars that wind up in the bss.
Line 1201 gives you this:
Code: Select all
0x00ff2508 _bend = .
Code: Select all
0x0002aafc _stext = SIZEOF (.text)