Class, Function and Pointer design speed questions
Hi, when you have a class or struct entity style, filled with data eg position, colour etc, would it be faster memory wise for a function to read them if they were pointed to instead of copied.
eg.
EntityClass myClass;
myClass.position= 343443;
myClass.colour = RED;
//using pointers in function void myFunction(EntityClass * data);
myFunction(&myClass);
//or using no pointers in function void myFunction(EntityClass data);
myFunction(myClass);
Thanks,
Why use a pointer at all when you can use a reference? I''m always amazed how you guys all strive to make everything complicated.
//using reference in function void myFunction(EntityClass& data);
myFunction(myClass);
And yeah, pass-by-reference (or by pointer if you really want to make your own life difficult), is generally faster than pass-by-value.
//using reference in function void myFunction(EntityClass& data);
myFunction(myClass);
And yeah, pass-by-reference (or by pointer if you really want to make your own life difficult), is generally faster than pass-by-value.
sometimes as i have realized in the past (thru my own experience) you get C and C++ mixed up and at times subconsciously pick and choose which features you''re gonna use.
but you''re right, he did make that unnecessarily complicated.
(warning, hijack) what language do you think promotes better programming habits? (plane is landing)
but you''re right, he did make that unnecessarily complicated.
(warning, hijack) what language do you think promotes better programming habits? (plane is landing)
quote:Original post by Alpha_ProgDes
(warning, hijack) what language do you think promotes better programming habits? (plane is landing)
(dodges the bullet)
References have been introduced to eliminate the ''pass by pointer'' idiom. If you''re programming in C, it''s perfectly fine. If you''re programming in C++, it''s bad style. It is not that C promotes bad programming habits; if anything the "bad habit" here is to ignore the differences in the languages: what will you do when you are facing a language that doesn''t have any pointers?
The whole point behind having multiple programming languages at your disposal is that they enable you to approach things differently. In the present case, I''d pick the C++ idiom by default and fall back on C when necessary - a number of C++ features have been introduced that explicitely deprecate (i.e. supercede) C features (e.g. namespaces, templates, references - figuring out what they replace in C is left as an exercise to the reader).
Much ink has been spent arguing what were "good programming habits", and I''m not even sure a full consensus can be reached. Each language has it''s own concept of "good style", and it is hard to say whether Prolog or Pascal promotes the best universal programming habits.
Anyway, just go learn python
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement