Skip to main content
GameDev.net gamedev.net
🔒 Locked

passing values to a function c++

Started by adam17 Apr 5, 2005 at 10:18 PM 3 replies 650+ views
Original Post
adam17
adam17
i have just a quick question. which is faster in vc++ 6, passing an entire sructure or passing just a pointer?
MaulingMonkey
MaulingMonkey
Quote:
Original post by Captain Logic
A pointer. Or a reference if you're using C++.


Unless the structure is very small (at least anything under 4 bytes, maybe up to as big as 8).

Unless the structure is very big, you probably won't _see_ a preformance difference either way.
ToohrVyk
ToohrVyk
If the structure is a POD, both methods will be equivalent for small structures, and it will be faster to pass the structure by reference if it is big.

For non-POD types, everything depends on the complexity of the copy constructor, but generally passing by reference is preferred.

If the function has a side-effect, such as storing the structure for later use, it is preferable to pass it either by value or by a smart shared pointer (see boost::shared_ptr).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.