On Wed, Feb 25, 2015 at 12:29 AM, <
jto...@gmail.com> wrote:
>
> It's probably to late to speak up about this, but the unintended side
> effects of this change to Go are tragic.
>
> Specifically, it is now impossible to implement an io.Reader or io.Writer
> using Cgo without doing a memory copy.
>
> For a specific use case, this means that
github.com/spacemonkeygo/openssl is
> going to require memory copies for all transport data when it totally
> doesn't need to.
>
> Is there any chance some kind of memory pinning for a []byte buffer is on
> the roadmap (I admit I can't imagine how it would work)? Passing in a []byte
> buffer into C as a data source/target is tremendously useful
> performance-wise.
We still have not pinned down the exact rules for this, and I
sincerely apologize for that. We've been distracted by other things.
However, let's not confuse the inability to pass Go pointers into C
code with the handling of buffers. I don't see any way that we can
support code such as the OP described, in which we pass a random Go
pointer into C code and the C code changes the memory to which that
pointer points. But passing buffers of data back and forth, data
which definitely does not contain pointers, is different. That may be
feasible. We don't know yet.
An approach that should certainly work is to allocate the byte buffers
in C and write into them in Go. This is certainly inconvenient, as
certain Go idioms such as using append to grow a slice will not work.
But it should be safe.
We're very aware of the issues with cgo, and we'll do our best to find
approaches that will work.
Ian