On Tue, Aug 22, 2017 at 1:35 PM MartinG <[email protected]> wrote:

> In the below code example, setting a function variable to a simple
function makes no memory allocation and is very fast (<1ns). The case of
setting the same function variable to a method value is much slower (~30ns)
and it turns out to be because memory is allocated there. (16 B/op)

A function variable is a pointer to a variable length structure containing
the function address and the closure of the function. f1's closure is
statically known (and empty) and is allocated once in the text or data
segment, myObj.myMethod's is dynamic (non empty and contains the receiver)
and thus must be created (allocated) at run time.

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to