Skip to content
Advertisement

Accessing C array in golang

I have two files, module.go and test.py. My goal is to speed up some calculations that is done in python, but have an issue accessing array of integers in go.

module.go

JavaScript

and simple test file in python:

JavaScript

After compiling go module with go build -buildmode=c-shared -o gomodule.so module.go and fire up python file I got:

JavaScript

I get that C array is different from Go, but can’t find any tutorial how to access it’s values without panic.

Advertisement

Answer

This is the idiomatic, efficient Go solution (avoid reflection).

module.go:

JavaScript

test.py:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement