Ok, I understand. So one has to be very careful when passing references
around because the underlying array will get changed but unless the
reference is copied back to the original reference the change won't be
reflected.if the size or capacity change. Are pointers to references then
the only way to do this type of manipulation?

On Friday, November 1, 2013 8:37:29 AM UTC, bobco...@gmail.com wrote:


I think I must be misunderstanding something.

I have 2 buffers to double buffer data.
They are created with zero length and capacity to hold the data that will
be written to them.
buf_1 = make ([]float64, 0, n)
buf_2 = make ([]float64, 0, n)

I then select which buffer to use by assigning it to a local variable.
var curr_buffer []float64 = buf_1
var next_buffer []float64 = buf_2

Now as I understand it I have a copy of the reference but the same
underlying data.

If I now append to say buf_1.
curr_buffer = append(curr_buffer, data...)

After the append the length of curr_buffer is len(data) but the length of
buf_1 is zero.
As the capacity was sufficient to hold the data I didn't expect a

I also tried this without the local variables by splitting the function
and passing the references - same result.

I then tried pointers to references which worked, but that was expected.

Can someone enlighten me on the mechanism going on here please.

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 12 | next ›
Discussion Overview
groupgolang-nuts @
postedNov 1, '13 at 12:29p
activeNov 3, '13 at 5:22p



site design / logo © 2022 Grokbase