3 ms·
That's a fine model when you want to hand a reference to a Go value, just to be used in Go itself, but it's not actual pinning. The data can still move, which m
by niemeyer 12y ago
That's a fine model when you want to hand a reference to a Go value, just to be used in Go itself, but it's not actual pinning. The data can still move, which means you cannot use the data in C, for example to share a buffer without copying into another temporary buffer managed by the C allocator.
- crawshaw 12y agoThat's right, you cannot dereference the pointer from C. If you want to use allocated memory from both C and Go, you'll need to allocate it in C.
- ominous_prime 12y agoWhat's the use-case for passing a pointer to C that can't be de-referenced?
- niemeyer 12y agoYou can pass it back into Go for dereferencing, at which point you can use the uintptr => unsafe.Pointer map, and it will be correct since the moving GC will have preserved the unsafe.Pointer address at the right location. The pattern is useful. It just doesn't handle the most common case, which is passing a buffer or a simple output parameter into a C function.
- deleted 12y ago[deleted]
- niemeyer 12y agoPlease note that the details aren't defined yet, and Ian indicates in a comment in this HN thread that some sort of pinning may exist. I also expect that to happen, given that a strict rule would break a lot of packages and turn what is today trivial into boring and slow code.