On 13/09/2018 3:22 AM, Timoses wrote:
On Wednesday, 12 September 2018 at 14:46:22 UTC, rikki cattermole wrote:
On 13/09/2018 2:34 AM, drug wrote:
12.09.2018 15:14, Timoses пишет:
On Tuesday, 11 September 2018 at 12:07:14 UTC, drug wrote:
If data size is less or equal to total size of available registers
(that can be used to pass values) than passing by value is more
efficient. Passing data with size less than register size by
reference isn't efficient because you pass pointer (that has
register size) and access memory using it.
Thank you!
So if I pass by reference it will ALWAYS use the address in memory
to fetch the data, whereas passing it by value enables the
(compiler?..) to use the register which has already loaded the data
from memory (stack for example)?
Honestly, I'm not an expert in this domain, but I think so.
Recently used areas of the stack will be available in the cache in
most cases. The issue with passing by reference is it increases the
indirection (number of pointers) that it must go through to get to the
raw bytes.
This is why classes are bad but structs are good. Even if the struct
is allocated on the heap and you're accessing it via a pointer.
This sounds like classes should never be used.. I don't recall right now
what issues I'm usually encountering with structs that make me switch to
classes (in D).
Nah, this is cycle counting aka don't worry about it if you're not doing
anything super high performance.