The buffers are part of my type state and get progressively filled from
another go routine, one of many. It may be I'm over egging it but don't
want to change the design. I've figured how to do it without using
pointers. My actual problem is corruption which gets progressively worse
the more parallel paths I have through my pipline which is 6 main go
routines. I'm going through making sure I understand the implications and
I'm much clearer on references now but I've still failed to find any where
I'm doing it wrong so far.
I do pass references around a lot, return them a lot and between go
routines the message format uses the interface{} to hold references as
these messages are of different types. In all case except the one I asked
the question about the slices are pre-allocated to correct length in a
memory allocator which re-cycles blocks (necessary because its real-time).

Am I right in thinking that as long as slice size does not change I can
throw them around, in and out of empty interface etc with impunity?

Thanks for the help so far. The Wiki ref was a good read.

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 | 8 of 12 | next ›
Discussion Overview
groupgolang-nuts @
postedNov 1, '13 at 12:29p
activeNov 3, '13 at 5:22p



site design / logo © 2022 Grokbase