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 

More efficient: pointer to structures data types or dynamic

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



Joined: 14 Oct 2005
Posts: 154

PostPosted: Mon Jun 05, 2006 1:36 am    Post subject: More efficient: pointer to structures data types or dynamic Reply with quote

Heres a quick question...

Are pointers to structures data types more efficient (AKA faster, less memory, etc.) rather then having a direct/dynamic call to the data type?

In lamen terms:

screen.x

or

screen->x

What is more efficient?
Back to top
View user's profile Send private message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Mon Jun 05, 2006 2:00 am    Post subject: Reply with quote

screen->x will be slower than screen.x due to the pointer indirection.

HOWEVER, you probably don't want to pass large structures around by value as function arguments just so you can skip some indirection in the function.
Back to top
View user's profile Send private message Visit poster's website
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Mon Jun 05, 2006 5:21 am    Post subject: Reply with quote

uhm, i wouldnt be sure about this....in many cases the generated assembly will be the same.
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Mon Jun 05, 2006 8:15 am    Post subject: Reply with quote

That's if the screen pointer is already in a register though, right?
Back to top
View user's profile Send private message Visit poster's website
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Mon Jun 05, 2006 9:27 am    Post subject: Reply with quote

in many (most) cases the compiler will load the base of the struct into a register and use that to access various members of the struct within a function. you have to keep in mind that even if the struct is a global static (which means its memory adress is known at compile time) can not be simply accessed without "pointer indirection". (there is no immediate load from a 32bit adress). also if the struct is local in a function, it will be created on the stack and thus the (a) pointer that can be used to access it IS already in a register. so while it does make a difference on other cpus, on mips (and other risc processors) the resulting code would be almost the same.[/code]
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Mon Jun 05, 2006 10:25 am    Post subject: Reply with quote

Neat.
Back to top
View user's profile Send private message Visit poster's website
ufoz



Joined: 10 Nov 2005
Posts: 86
Location: Tokyo

PostPosted: Mon Jun 05, 2006 3:16 pm    Post subject: Reply with quote

More importantly, if this is the sort of optimization you're worried about, chances are you're wasting your time...
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
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