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
airbuff
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
W Pirkle
Admin
October 21, 2013 - 7:04 pm
Member Since: January 29, 2017
Forum Posts: 573
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
airbuff
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:
10 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Chaes: 51

Skyler: 48

Derek: 46

Frodson: 45

Peter: 43

TheSmile: 43

clau_ste: 39

jim: 34

JimmyM: 33

Gwen: 32

Member Stats:

Guest Posters: 1

Members: 696

Moderators: 1

Admins: 5

Forum Stats:

Groups: 13

Forums: 41

Topics: 757

Posts: 2894

Newest Members:

Jas, Rowan, sojourn, fabhenr, rg1, Niklas, Wutru, Tim Campbell, Danny Jonel, Valentin

Moderators: W Pirkle: 573

Administrators: Tom: 74, JD Young: 80, Will Pirkle: 0, W Pirkle: 573, VariableCook: 3