Issue: The RocksDB C++ Get function takes in a std::string
pointer. The current C API will copy that into a char array (not null-terminated C string). This copy seems redundant.
To remove this copying, one direction is to have a Go wrapper around a C++ string. Here is my attempt. It seems to work fine.
Previously I was worried about the garbage collection not freeing the C++ string. The solution is to use runtime.SetFinalizer
. I verified in a sample run that the C++ string does get deallocated properly when GC runs.
SetFinalizer
does look hacky. And the user must not do anything to the read-only data returned from C++ string. If you all are ok with this, I will try integrating it into our RocksDB wrapper code.