Copy data when passing slice via channel
This commit is contained in:
parent
d815c08aaa
commit
f374a92568
|
@ -136,5 +136,7 @@ func (g *Gaborator) analyze(block []float32) {
|
|||
|
||||
//export cgoCallback
|
||||
func cgoCallback(ptr C.uintptr_t, data *C.float, size C.int) {
|
||||
cgo.Handle(ptr).Value().(chan []float32) <- unsafe.Slice((*float32)(data), int(size))
|
||||
buf := make([]float32, size)
|
||||
copy(buf, unsafe.Slice((*float32)(data), int(size)))
|
||||
cgo.Handle(ptr).Value().(chan []float32) <- buf
|
||||
}
|
||||
|
|
|
@ -36,9 +36,8 @@ func TestGoborator(t *testing.T) {
|
|||
|
||||
var i = 0
|
||||
start := time.Now()
|
||||
//for c := range ob.GaborTransform(channel) {
|
||||
for _ = range ob.GaborTransform(channel) {
|
||||
//fmt.Printf("%d: %+F\n", i, c)
|
||||
for c := range ob.GaborTransform(channel) {
|
||||
fmt.Printf("%d: %+F\n", i, c)
|
||||
i++
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue