On Fri, Apr 13, 2018 at 2:07 PM, Yulrizka <yulri...@gmail.com> wrote:
>
> I'm playing around with slices.
> Found that slice of bytes with the size more than 10485760 is moved to the
> heap.

Because Go stacks are copied as needed, there is a tradeoff between
putting a value on the stack and putting it on the heap.  On the heap
it requires a memory allocation.  On the stack it may potentially be
copied multiple times.  So it seems reasonable to put very large
values in the heap.  That tradeoff is baked into the compiler in the
form of the constant maxStackVarSize, whose value is indeed 10 * 1024
* 1024.

Ian

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to