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 > malloc() not working

#46917 - headspin - Sat Jul 02, 2005 1:36 am

Hi, currently I have a variable I use to store large sample data.

Code:
#define MAXSMP   (44100*10)

short VAR_IN_EXRAM MemWav[MAXSMP];


To save taking such a long time to send via wifime, I'd like to malloc it at run-time.

I use this code:

Code:
short *MemWav;


Then in main() I allocate memory (I've tried both these methods):

Code:
MemWav = new short[MAXSMP];
// or
MemWav = (short *) malloc(MAXSMP);


I assume they are essentially the same since new calls malloc, am I correct?

This is crashing my ROM using either of these methods. I should probably place it in external RAM, how can I do that using malloc/new?

I have tried replacing ds_arm9.ld from this thread, but still not working.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game


Last edited by headspin on Sat Jul 02, 2005 5:46 pm; edited 1 time in total

#46925 - notb4dinner - Sat Jul 02, 2005 4:51 am

short = 2 bytes, so the correct form would be:
MemWav = (short *) malloc(MAXSMP*sizeof(short));

However since the array method is crashing as well that's probably not the source of your problem.

#46933 - headspin - Sat Jul 02, 2005 6:10 am

Thanks for the reply, of course cos malloc takes size as bytes.. but still CRASH!

Shouldn't malloc'ed stuff be placed in EXRAM? I think that's the problem perhaps. Any way to specify the allocation to be external RAM?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#46934 - LOst? - Sat Jul 02, 2005 6:28 am

headspin wrote:
This is crashing my ROM using either of these methods.


Using your ROM with an specific emulator, or the real hardware?

#46935 - headspin - Sat Jul 02, 2005 6:31 am

my ROM won't work in emulator, acutally I can't get anything working in any emulators at all (even ndslib examples), the emu's just crash for me :(

Anyways, I use both processors so emulator will not work anyways.

So this is a multiboot ROM which I test by sending wirelessly using wmb.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#46936 - LOst? - Sat Jul 02, 2005 6:39 am

headspin wrote:
my ROM won't work in emulator, acutally I can't get anything working in any emulators at all (even ndslib examples), the emu's just crash for me :(


I wonder how long it will take before emulators will work. I get a lot of crashes and random results everytime I recompile my code.

Try run your ROM without multiboot support. Maybe you will have better luck with malloc. Myself has almost lost every hope of getting my DS 2D engine to work because things won't work as they are supposed to.

#46937 - headspin - Sat Jul 02, 2005 6:43 am

My ROM works fine when I set the variable size and store it in EXRAM. But as you can imagine it adds about 500k to the ROM size.

If I use malloc() I can allocate at runtime and make my ROM size smaller.

I want my ROM to be multiboot so people can send it wirelessly.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#46942 - Mollusk - Sat Jul 02, 2005 8:48 am

Headspin, first thing, even if it adds 500k to the rom, this shouldn't change the multiboot ability, right ? Multiboot means all will be put in RAM, so if you're rom is already around 4 megs, you won't be able to add the extra 500k to ram... so if the ROM size is ok with the variables in it, even with 500 extra k, it should work.

Second, can't you use the BSS ? (#define EWRAM_BSS __attribute__((section(".sbss"))) in ndslib) It should, if I get it right, put the data in EWRAM but not in the rom, so you would get a smaller rom size... It just creates it at the startup...

#46962 - gladius - Sat Jul 02, 2005 6:05 pm

Mollusk is 100% right. VAR_IN_EXRAM is used for initialized variables that you want to place in EWRAM, for unitialized variables, use EWRAM_BSS, which will not increase the size of your rom.

#46983 - headspin - Sun Jul 03, 2005 1:34 am

Thanks, it worked :)
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#46986 - LOst? - Sun Jul 03, 2005 3:21 am

headspin wrote:
Thanks, it worked :)

Lucky you. I wish my stuff would work to.


How big size is the EWRAM_BSS area?