On Wed, Jan 24, 2018 at 3:00 PM, Christian LeMoussel
wrote:
> Thank you Bryan for your advice.
> In examples, I see how to pass the Go pointers directly.
>
> For example :
> h := C.CString(name)
> defer C.free(unsafe.Pointer(h))
> gerrno, err := C.getaddrinfo(h, nil, &hints, &res)
> T
Thank you Bryan for your advice.
In examples, I see how to pass the Go pointers directly.
For example :
h := C.CString(name)
defer C.free(unsafe.Pointer(h))
gerrno, err := C.getaddrinfo(h, nil, &hints, &res)
To
h := make([]byte, len(name)+1)
copy(h, name)
gerrno, err := C
It may be considerably more efficient to pass the Go pointers directly.
To do so, you may need to convert through unsafe.Pointer.
Note that many C APIs that take a char* expect it to be null-terminated, so
if you take that approach you may need to append an extra 0 to the slice.
https://golang.o
On Tue, Jan 23, 2018 at 5:02 PM Christian LeMoussel
wrote:
> Is it correct /best way ?
Hopefully/only. But as noted previously, not tested.
> There is no memory leaks ?
Something must eventually C.free() the memory allocated by C.CString().
--
-j
--
You received this message because you
I do this
devidx := C.scan_bus((*C.char)(unsafe.Pointer(&sbuf[0])),
C.int(cap(sbuf)), C.CString(sn), C.CString(product))
Is it correct /best way ?
There is no memory leaks ?
.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsu