Re: [go-nuts] The memory release about Turning C arrays into Go slices

2017-08-21 Thread jianzhangbjz
Sorry for late reply, thanks very much! I will have a try. 在 2017年8月18日星期五 UTC+8下午4:23:07,Konstantin Khomoutov写道: > > On Fri, Aug 18, 2017 at 10:39:29AM +0300, Konstantin Khomoutov wrote: > > [...] > > There can't be easy answer to a question like this in C. > > Consider: > > > > // This fu

Re: [go-nuts] The memory release about Turning C arrays into Go slices

2017-08-18 Thread Konstantin Khomoutov
On Fri, Aug 18, 2017 at 10:39:29AM +0300, Konstantin Khomoutov wrote: [...] > There can't be easy answer to a question like this in C. > Consider: > > // This function clearly transfers the ownership of the memory > // it returns to the caller. > int* allocate(int n) > { > int *mem =

Re: [go-nuts] The memory release about Turning C arrays into Go slices

2017-08-18 Thread Konstantin Khomoutov
On Thu, Aug 17, 2017 at 06:50:42PM -0700, jianzhang...@gmail.com wrote: > > > As the instruction > > > of https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices > > > shows, the GC of Go will not release it. > > > An example as the following, but I have a question about when and

Re: [go-nuts] The memory release about Turning C arrays into Go slices

2017-08-17 Thread jianzhangbjz
Thanks your reply, you mean I should be release the memory of `theCArray` in C side? I still have some doubts, and I made a clearer example as the below, any problem with it? So, the memory of this tmpslice should be release by release the argv on C side? func GoStrings(length int, argv **C.ch

Re: [go-nuts] The memory release about Turning C arrays into Go slices

2017-08-17 Thread Konstantin Khomoutov
On Thu, Aug 17, 2017 at 03:32:28AM -0700, jianzhang...@gmail.com wrote: > As the instruction > of https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices > shows, the GC of Go will not release it. > An example as the following, but I have a question about when and how to > release

[go-nuts] The memory release about Turning C arrays into Go slices

2017-08-17 Thread jianzhangbjz
As the instruction of https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices shows, the GC of Go will not release it. An example as the following, but I have a question about when and how to release this `slice`? import "C" import "unsafe" ... var theCArray *C.YourType =