| View previous topic :: View next topic |
| Author |
Message |
CheChin
Joined: 04 Aug 2005 Posts: 8
|
Posted: Fri Aug 05, 2005 9:34 pm Post subject: memory issues with structs? |
|
|
it's hard to explain, so here's an example.
my structs are defined like this:
| Code: | typedef struct {
double x;
double y;
double dx;
double dy;
int carrier;
int avoid;
} BALL_STRUCT;
typedef struct {
double x;
double y;
double dx;
double dy;
double sa;
int team;
int keys;
int coll;
} USER_STRUCT;
typedef struct {
double x;
double y;
double delta;
double dest;
} GLIE_STRUCT; |
then i make the objects with theese types:
| Code: | BALL_STRUCT ball;
USER_STRUCT user[USER_COUNT - 1];
GLIE_STRUCT goalie[GOALIE_COUNT - 1]; |
then i set the initialization values:
| Code: | ball.x = 240;
ball.y = 136;
ball.avoid = 255;
ball.carrier = 255;
user[0].x = 50;
user[0].y = 136;
user[0].team = 0;
user[1].x = 430;
user[1].y = 136;
user[1].team = 1;
goalie[0].x = 4;
goalie[0].y = 136;
goalie[1].x = 476;
goalie[1].y = 136; |
this results in ball.x having a value of 476, AND continue to get that value even after i alter goalie[1].x again. Why is that? |
|
| Back to top |
|
 |
mc

Joined: 12 Jan 2005 Posts: 212 Location: Linköping
|
Posted: Fri Aug 05, 2005 9:59 pm Post subject: |
|
|
Let me guess... GOALIE_COUNT (and USER_COUNT) is 2? In that case you are writing outside the arrays and trashing memory. You probably made some kind of thought lapse when you wrote [...COUNT - 1] instead of [...COUNT]. _________________ Flying at a high speed
Having the courage
Getting over crisis
I rescue the people |
|
| Back to top |
|
 |
ReKleSS

Joined: 18 Jun 2005 Posts: 73 Location: Melbourne, Australia
|
Posted: Fri Aug 05, 2005 10:12 pm Post subject: |
|
|
Also, on a half-related note, from what I recall the psp works considerably faster with floats than with doubles. You probably shouldn't be using doubles unless you really need the precision.
-ReK |
|
| Back to top |
|
 |
CheChin
Joined: 04 Aug 2005 Posts: 8
|
Posted: Mon Aug 08, 2005 7:43 am Post subject: |
|
|
thanx mc, that was the case. works perfectly now.
all the vars' were origionally floats, but i changed em since i thought doubles was faster. thanx for the information, ReKleSS |
|
| Back to top |
|
 |
|