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.

DS development > li'l trouble with arrays...

#47490 - Sephiroth87 - Sat Jul 09, 2005 5:20 pm

hi...
i've a li'l prob with a big array i'm going to use...

it's defined as unsigned char memory[0x10000], ad it's compiled right...

but when i try to put something inside it, if i put it in a low addres, like memory[0x2000], it works...

but if i try to put in a high addres like memory[0xE000], the array remains void...

the strange thing is that if i try to look in the array, some slots are occupied by something that is not mine...

i don't believe that ds has less than 16k of ram...
what can i do? i need this big array...

#47491 - gladius - Sat Jul 09, 2005 5:28 pm

As per the many other topics about this sort of problem, use EWRAM_BSS or VAR_IN_EXRAM if it is initialized to put the variable into the 4mb ewram.

I'll quote myself on how to do this:
Quote:

Currently, the DevkitArm compiler puts all variables and static arrays into the DTCM region, which is only 32Kb. So if your program has more than 32Kb of variables+arrays declared (note, arrays that are malloc()'ed are okay) then you will get that error.

You can work around this by adding EWRAM_BSS to the end of any uninitialized variables that are not speed critical, so they will be put into main ram. If they are initialized, use VAR_IN_EXRAM. So something like this:

u8 array[0x1000]; <-- original
u8 array[0x1000] EWRAM_BSS; <--- new

u32 values[0x10] = {0,0,0,0...}; <-- original
u32 values[0x10] VAR_IN_EXRAM = {0,0,0,0...}; <---new

#47494 - Sephiroth87 - Sat Jul 09, 2005 5:58 pm

oh, tnx so much...
but, in case i need a little speed up, how can i malloc it?

#47498 - gladius - Sat Jul 09, 2005 7:08 pm

Malloc only allocates memory from ewram. From a speed perspective it is exactly the same as using EWRAM_BSS.

#47501 - Sephiroth87 - Sat Jul 09, 2005 8:00 pm

perfect, so i'm done :D

thank'you soo much ;)