Copy data when passing slice via channel

This commit is contained in:
DataHoarder 2022-01-29 06:11:06 +01:00
parent d815c08aaa
commit f374a92568
2 changed files with 5 additions and 4 deletions

View file

@ -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
}

View file

@ -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++
}