#4682 - johnny_north - Mon Apr 07, 2003 12:04 am
This is my problem...
If I include a declaration of this class:
class ClearBlocks{
short x;
short y;
short which;
bool active;
};
in another class:
class Piece{
...(other vars)
ClearBlocks cb[40];
...
}
my code hangs during the first graphic. However, if I do this:
class Piece{
...(other vars)
short x[40];
short y[40];
short which[40];
bool active[40];
...
}
everything runs just fine? Seems like this should be the same, just less organized. I'm using the original devkit, compiling in ARM. Can anyone help?
#4684 - niltsair - Mon Apr 07, 2003 1:46 am
First thing, you should either do:
Code: |
struct ClearBlocks{
short x;
short y;
short which;
bool active;
}; |
or
Code: |
class ClearBlocks{
public:
short x;
short y;
short which;
bool active;
}; |
Because all members of a class are private by default(not accessible from outside the class) while all members of a struct are public.
#4685 - johnny_north - Mon Apr 07, 2003 1:56 am
I actually did start by using your struct example, but the accessability of the members doesn't affect the problem. These members are actually meant to be private as the class will have its own member functions.
The devkit compiler doesn't like the struct and class types. I thought it might have something to do with alignment issues (I've had to align const arrays that hold graphics), but I've tried to do some padding and it doesn't seem to help.
Anyone know - is there a lot of overhead with a struct or class? Anyone know how many bytes?
#4690 - johnny_north - Mon Apr 07, 2003 3:11 am
Ok, after messing with this a bit I might suspect that I'm running out of room for variables. I've got quite a number of them in class headers, and so all of them are in memory at any given time. After optimizing variable usage in several classes, the:
ClearBlocks cb[40]
seems to work. Question is, what's my limit. If I remember right, I think that all of the variables in each instace of all current classes are pushed onto the stack. I went looking into Jeff F's crt0.s:
__text_start = DEFINED (__gba_multiboot) ? 0x2000000 : 0x8000000;
/* __ewram_start = 0x2000000; */ /* Removed in v1.3 */
__eheap_end = 0x2040000;
__iwram_start = 0x3000000;
__iheap_end = 0x3008000 - 0x400;
__sp_usr = 0x3008000 - 0x100;
__sp_irq = 0x3008000 - 0x60;
__intr_vector_buf = 0x3008000 - 4;
__sp_usr_offset = __sp_usr - __iwram_start;
__intr_vect_offset = __intr_vector_buf - __sp_usr;
I'm confused here. Is sp_usr a pointer to the stack, and how many bytes is it? Also, because of alignment issues, if I use a u8 variable, does the compiler allocate 4 bytes anyway?
Thanks for the help!
#4700 - Quirky - Mon Apr 07, 2003 7:42 am
Use the -Map linker option to see where your variables are going. Your limit, assuming that these variables haven't been assigned to go in EWRAM, is 32k.