c++ - C/ObjC - parameter size. Using a pointer vs value -


at point should passing pointer data in functions/methods, rather passing value?

obviously there's cases want function operate on given data, if i'm passing value info/copying purposes?

for example, foo basic type:

void setfoo(int foo); ... int foo = 1; setfoo(foo); 

now foo simple structure:

typedef struct {     int x;     int y; } foo;  void setfoo(foo foo); ... foo foo = {1, 2}; setfoo(foo);   // apple code kind of thing cgsize, cgpoint... 

but if foo bigger struct...

typedef struct {     int x;     int y;     int z;     char str[256]; } foo;  void setfoo(foo *foo);  // taking pointer instead. ... foo foo = {1, 2, 3, etc ... }; setfoo(&foo); 

q. @ point here should start using pointer when providing data function?

thanks

when on embedded systems, think it's practice pass pointers (or references) that's not primitive type. way struct can grow , add members needed without affecting amount of data copied. needless copying way slow down system, avoid when can. getting habit in long run think.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -