miekg / pkcs11

pkcs11 wrapper for Go
BSD 3-Clause "New" or "Revised" License
375 stars 133 forks source link

Remove unnecessary memory copies by C.GoBytes() calls #154

Closed ansiwen closed 2 years ago

ansiwen commented 2 years ago

It is not necessary to copy the memory in order to get a []byte representation of Go allocated memory, because the GC will take care of the lifetime of the underlying memory. This change introduces the memBytes() function, that returns a slice to an arbitrary memory area, and replaces all uses of C.GoBytes with Go allocated memory. This function could even be used for C allocated memory, but then the caller has to make sure that the underlying C memory is not freed during the lifetime of the returned slice.

Signed-off-by: Sven Anderson sven@anderson.de

miekg commented 2 years ago

thanks for the checking!

I think this is OK to merge.