I recently wrote cgo bindings to the CTIDH C library (a bleeding edge post 
quantum non-interactive key exchange) copies the data twice. First in the 
call to C.CBytes and then again in the assignment to p.privateKey via that 
pointer dereference.

The performance hit for the twice copy is not really a problem. I'm just 
curious, is there's a more proper way to write this that avoids the twice 
copy?


// FromBytes loads a PrivateKey from the given byte slice.
func (p *PrivateKey) FromBytes(data []byte) {
   key := C.CBytes(data)
   defer C.free(key)
   p.privateKey = *((*C.private_key)(key))
}

https://git.xx.network/elixxir/ctidh_cgo/-/blob/master/binding.go#L49-54


Sincerely,
David

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3b8a9098-aabb-4b53-933e-b4e4b6e21cdcn%40googlegroups.com.

Reply via email to