Re: [go-nuts] What's going on while using "append" in memory?

2021-08-10 Thread Marvin Renich
* Henry [210810 01:26]: > Just sharing some tips. > > When working with slices, it is often a good idea to lend a helping hand to > the compiler. > > Don't declare something like this, unless you have no other choices. > ``` > var slice []int > ``` I believe this is bad advice. First, if «sl

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-09 Thread Henry
Just sharing some tips. When working with slices, it is often a good idea to lend a helping hand to the compiler. Don't declare something like this, unless you have no other choices. ``` var slice []int ``` If you know the data right away, you can do something like this: ``` slice := []int{1,2,

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-08 Thread Miraddo
Thanks, Brain. It is absolutely fantastic. I saw this SliceTricks two days ago. Nice to mention it. On Sunday, August 8, 2021 at 8:36:27 PM UTC+4:30 Brian Candler wrote: > On Friday, 6 August 2021 at 18:00:35 UTC+1 Konstantin Khomoutov wrote: > >> Have you read and understood [1] and [2]? >> >

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-08 Thread Miraddo
Henry Thanks for your time, You're right. Sounds reasonable. But you know, the first time I saw this thing, I was like, when I pass the new slice to my existing slice, does it not replace the item in the same address in memory that my slice has before? Because when I pass new data to my variabl

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-08 Thread Miraddo
Thank you, Konstantin. I really appreciate your response, I didn't read those links before you sent them to me, but I read them yesterday, now everything is so clear to me, and I know what is going on with "slice," "append," and "copy" in memory. I was so confused, but now I know what's going on

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-08 Thread Brian Candler
On Friday, 6 August 2021 at 18:00:35 UTC+1 Konstantin Khomoutov wrote: > Have you read and understood [1] and [2]? > ... > 1. https://blog.golang.org/slices-intro > 2. https://blog.golang.org/slices > > Also possibly of interest (although it doesn't mention rotation): https://github.com/golang/

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-08 Thread Henry
Append is for appending items at the end of a slice. If there is enough space, Go will simply append the items and return the slice. If there is not enough space, Go will create a new slice with double the capacity of the existing slice or at least enough space to hold the new items (whichever

Re: [go-nuts] What's going on while using "append" in memory?

2021-08-06 Thread Konstantin Khomoutov
On Fri, Aug 06, 2021 at 12:42:34AM -0700, Miraddo wrote: Hi! > I can not understand why when we use append, it does not rewrite values in > the same address in the memory that it had before, > > (I'm not sure it "append" problem or the variable | or just my problem for > sure :) ) [...] > I

[go-nuts] What's going on while using "append" in memory?

2021-08-06 Thread Miraddo
Hello all, I can not understand why when we use append, it does not rewrite values in the same address in the memory that it had before, (I'm not sure it "append" problem or the variable | or just my problem for sure :) ) let me explain what I mean, I solve a question in LeetCode (189. R