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 > libfat and fread

#161019 - mfallon - Sat Jul 26, 2008 9:14 am

Does anyone know why this works fine:

unsigned int *splashTiles=new unsigned int[3632];
FILE *file=fopen(path,"rb");
fread(splashTiles,4,3632,file);
fclose(file);

While this crashes inside of fread on two emulators and hardware:

unsigned int splashTiles[3632];
FILE *file=fopen(path,"rb");
fread(splashTiles,4,3632,file);
fclose(file);

I even tried pulling it out of my code and isolating it to make sure there wasn't some other memory issue going on.

Thanks,

Matt

#161020 - Dwedit - Sat Jul 26, 2008 9:21 am

Is the stack that big? I bet that allocating 14.5k off the stack is never a good idea.

Usually the stack is put into DTCM, which is 16k in size. I bet libfat would use up to 1k of stack before it returns.

When you use new or malloc, you allocate from the heap. The heap is in the 4MB main memory, located right after the end of your NDS program.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#161021 - mfallon - Sat Jul 26, 2008 9:34 am

That makes sense. I was planning on using dynamic allocation anyway and had just tried the other as a quick test to see if I had the graphics file formatted correctly and was curious why it was failing.

Thanks,

Matt