forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

memory issues with structs?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
CheChin



Joined: 04 Aug 2005
Posts: 8

PostPosted: Fri Aug 05, 2005 9:34 pm    Post subject: memory issues with structs? Reply with quote

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
View user's profile Send private message
mc



Joined: 12 Jan 2005
Posts: 212
Location: Linköping

PostPosted: Fri Aug 05, 2005 9:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
ReKleSS



Joined: 18 Jun 2005
Posts: 73
Location: Melbourne, Australia

PostPosted: Fri Aug 05, 2005 10:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
CheChin



Joined: 04 Aug 2005
Posts: 8

PostPosted: Mon Aug 08, 2005 7:43 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group