| View previous topic :: View next topic |
| Author |
Message |
sg57
Joined: 14 Oct 2005 Posts: 154
|
Posted: Mon Jun 05, 2006 1:36 am Post subject: More efficient: pointer to structures data types or dynamic |
|
|
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 |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Mon Jun 05, 2006 2:00 am Post subject: |
|
|
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 |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
|
| Back to top |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Mon Jun 05, 2006 8:15 am Post subject: |
|
|
| That's if the screen pointer is already in a register though, right? |
|
| Back to top |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
Posted: Mon Jun 05, 2006 9:27 am Post subject: |
|
|
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 |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Mon Jun 05, 2006 10:25 am Post subject: |
|
|
| Neat. |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Mon Jun 05, 2006 3:16 pm Post subject: |
|
|
| More importantly, if this is the sort of optimization you're worried about, chances are you're wasting your time... |
|
| Back to top |
|
 |
|