Your Universal Remote Control Center
RemoteCentral.com
Custom Installers' Lounge Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 55 made on Saturday February 22, 2020 at 02:36
davidcasemore
Super Member
Joined:
Posts:
January 2003
3,352
On February 21, 2020 at 19:44, Lowhz said...
It's just faster to use aliases:

The reason, via Stackoverflow

The cost of passing a struct is proportional to its size. If the struct is smaller than a reference or the same size as a reference then passing its value will have the same cost as passing a reference.

If not, then you are correct; copying the struct might be more expensive than copying the reference. That's why the design guidelines say to keep a struct small.

(Note that when you call a method on a struct, the "this" is actually passed as a reference to the variable that contains the struct value; that's how you can write a mutable struct.)

There are potential performance gains when using structs, but as you correctly point out, there are potential performance losses as well. Structs are cheap (in both memory and time) to allocate and cheap to deallocate (in time), and cheap to copy if they are small. References are slightly more expensive in both memory and time to allocate, more expensive to deallocate, and cheap to copy. If you have a large number of small structs -- say, a million Point structs -- then it will be cheaper to allocate and deallocate an array with a million structs in it than an array with a million references to a million instances of a Point class.

But if the struct is big, then all that additional copying might be more expensive than the benefit you get from the more efficient allocation and deallocation. You have to look at the whole picture when doing performance analysis; don't make the "struct vs class" decision on the basis of performance without empirical data to back up that decision.

Is this true at the Quantum level as well?
Fins: Still Slamming' His Trunk on pilgrim's Small Weenie - One Trunk at a Time!


Hosting Services by ipHouse