Maybe there is a more efficient way than calling back and forth between managed and unmanaged code for every function call.