Cgo - safe a reference to a go object - "export-handle" problem

Hi, this is my first post an question regarding GO and CGO.

I need to store a GO reference in C. currently I use the following pseudo-code:

  1. create a global map
    var lockService = make(map[MyUUID]MyInterface)
    (this is not thread-safe)

  2. save the MyUUID (which have the max length of a C-Pointer, 64bit) in C
    var uid MyUUID = (generate)
    lockService[uid] = MyInterfaceObject

  3. get my MyInterface back with:
    uid := C.MyUUIDget()

Question: is there a go “builtin” to solve the “export-handle” problem?

I think your solution, generating handles yourself and passing them to C instead of Go pointers, is about as good as it gets.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.