Reference, pointer and value efficiency | General C++ Topics | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Reference, pointer and value efficiency
Avatar
Member
Members
October 21, 2013 - 3:16 pm
Member Since: October 2, 2013
Forum Posts: 14
sp_UserOfflineSmall Offline

When passing a primitive data type (float) which is not supposed to be altered to a methode, what is most efficent way:
- Passing by value
- Passing a pointer (const const)
- Passing a const reference

Avatar
Admin
October 21, 2013 - 7:04 pm
Member Since: January 29, 2017
Forum Posts: 693
sp_UserOfflineSmall Offline

The overhead is from local copying and storage of the parameters. Pass By Reference does not involve copying or storing the copied value so technically it is the fastest. When you pass by pointer, a copy of the pointer is made (just like pass by value) so that you can not alter the pointer's value but you can alter the underlying variable. So it is the same as pass by value.

- Will

Avatar
Member
Members
October 21, 2013 - 8:39 pm
Member Since: October 2, 2013
Forum Posts: 14
sp_UserOfflineSmall Offline

interesting, thank you. I wondered if copying or dereferencing might be faster.

Forum Timezone: America/New_York

Most Users Ever Online: 152

Currently Online:
2 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Chaes: 56

Skyler: 48

StevieD: 46

Derek: 46

Frodson: 45

Peter: 43

TheSmile: 43

Nickolai: 43

clau_ste: 39

jeanlecode: 37

Member Stats:

Guest Posters: 2

Members: 784

Moderators: 1

Admins: 6

Forum Stats:

Groups: 13

Forums: 42

Topics: 850

Posts: 3372

Moderators: W Pirkle: 693