Slightly better example to above
https://play.golang.org/p/eGCw4ldGiZ
both pointer checks fail, but initially the underlying arrays are the same,
not so after the append.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from thi
On Monday, 13 March 2017 21:14:27 UTC, Dave Cheney wrote:
>
> A few clarifications, b does not point to a. a and b are variables of type
> []int. The value of each slice's ptr fields point to a backing array of
> some capacity.
>
> If you append to a, this does not change th length or cap fiel
A few clarifications, b does not point to a. a and b are variables of type
[]int. The value of each slice's ptr fields point to a backing array of some
capacity.
If you append to a, this does not change th length or cap fields of b. If you
do this enough times that ptr field of a will be updat
On Monday, 13 March 2017 07:20:57 UTC, Jan Mercl wrote:
> On Mon, Mar 13, 2017 at 8:05 AM st ov >
> wrote:
>
> > I know it can be accessed the question relates to this
> >
> http://stackoverflow.com/questions/36706843/how-to-get-the-underlying-array-of-a-slice-in-go
>
> Let me ask what do
just a thought experiment :)
On Monday, March 13, 2017 at 12:20:57 AM UTC-7, Jan Mercl wrote:
>
> On Mon, Mar 13, 2017 at 8:05 AM st ov >
> wrote:
>
> > I know it can be accessed the question relates to this
> >
> http://stackoverflow.com/questions/36706843/how-to-get-the-underlying-array-of-a-
On Sun, 12 Mar 2017 17:36:53 -0700 (PDT)
st ov wrote:
> > > What happens when appending to a slice exceeds the backing
> > > capacity?
> >
> > If the capacity of s is not large enough to fit the additional
> > values, append allocates a new, sufficiently large underlying array
> > that fits both
On Mon, Mar 13, 2017 at 8:05 AM st ov wrote:
> I know it can be accessed the question relates to this
>
http://stackoverflow.com/questions/36706843/how-to-get-the-underlying-array-of-a-slice-in-go
Let me ask what do you need the backing array for which cannot be done
using the slice value? Using
I know it can be accessed the question relates to this
http://stackoverflow.com/questions/36706843/how-to-get-the-underlying-array-of-a-slice-in-go
On Sunday, March 12, 2017 at 10:01:11 PM UTC-7, Jan Mercl wrote:
>
> What is a reference to the array? To access the array use the slice itself
> a
What is a reference to the array? To access the array use the slice itself
as usual, no reflect needed.
On Mon, Mar 13, 2017, 01:37 st ov wrote:
> Thanks!
> anyway to get a reference to that new array without using reflect?
>
>
>
>
> On Sunday, March 12, 2017 at 12:13:03 PM UTC-7, Jan Mercl wrot
Thanks!
anyway to get a reference to that new array without using reflect?
On Sunday, March 12, 2017 at 12:13:03 PM UTC-7, Jan Mercl wrote:
>
> On Sunday, March 12, 2017 at 11:49:33 AM UTC-7, st ov wrote:
>
> > What happens when appending to a slice exceeds the backing capacity?
>
> If the capac
On Sunday, March 12, 2017 at 11:49:33 AM UTC-7, st ov wrote:
> What happens when appending to a slice exceeds the backing capacity?
If the capacity of s is not large enough to fit the additional values,
append allocates a new, sufficiently large underlying array that fits both
the existing slice
pasting code for convenience
func main() {
// create backing array
arr := [5]int {0,1,2,3,4}
fmt.Println(arr)
// take a slice of backing array
s1 := arr[:3]
fmt.Println(s1)
fmt.Println(arr)
fmt.Println(cap(s1))
// append to slice, replaces backing
12 matches
Mail list logo