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 sp_TopicIcon
Reference, pointer and value efficiency
No permission to create posts
October 21, 2013
3:16 pm
Avatar
airbuff
Member
Members
Forum Posts: 14
Member Since:
October 2, 2013
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

October 21, 2013
7:04 pm
Avatar
W Pirkle
Admin
Forum Posts: 140
Member Since:
January 28, 2017
sp_UserOnlineSmall Online

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

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

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

Forum Timezone: America/New_York

Most Users Ever Online: 36

Currently Online: W Pirkle
3 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 47

Derek: 41

Peter: 41

clau_ste: 39

Frodson: 38

Gwen: 32

EZB: 24

lppier: 23

Msaldaña: 18

Jorge: 17

Member Stats:

Guest Posters: 1

Members: 478

Moderators: 1

Admins: 4

Forum Stats:

Groups: 11

Forums: 29

Topics: 479

Posts: 1870

Newest Members:

certvalue111, sobhana s, sam, annaharris, Marie Weaver, kev, Steven, Mr Anderson, mguy, omelc

Moderators: W Pirkle: 140

Administrators: Tom: 65, JD Young: 80, Will Pirkle: 0, W Pirkle: 140