using a p/invoke wrapper

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

We are using SQLite.net in an application but getting a bottleneck at
the data access layer (it has been profiled). This is clearly because
p/invoke takes 5 to 10 times longer than it does calling the function
straight from C/C++ code.
Is it possible to write a wrapper in Managed C++ that provides a managed
interface to the SQLite API, but still accesses the SQLite API directly
(without using p/invoke)?

Chris
 
Chris said:
We are using SQLite.net in an application but getting a bottleneck at
the data access layer (it has been profiled). This is clearly because
p/invoke takes 5 to 10 times longer than it does calling the function
straight from C/C++ code.
Is it possible to write a wrapper in Managed C++ that provides a
managed interface to the SQLite API, but still accesses the SQLite
API directly (without using p/invoke)?

Are you *sure* it is pinvoke that is causing the problem? I ask because
if you are making a call to unmanaged code from managed code then by
definition at some point you will have to make a managed/unmanaged
transition. There really isn't much difference between pinvoke and IJW
(used by managed C++) in terms of performance.

You may have problems marshalling data, or with memory management
issues, but it should be possible to fix those issues without having to
resort to a managed C++ wrapper. Your statement that it is 5 to 10 times
longer with a managed caller than with a unmanaged caller is a bit odd
since a pinvoke call *should* only add a few tens of extra machine
cycles to the call. If you are not marshalling the data correctly, or if
buffers are unnecessarily being allocated tht could explain the problem.

Richard
 
What code are you using to compare the C++ and managed wrapper?

In my tests, the ADO.NET wrapper easily got between 90% and 98% of the
performance of raw C access to SQLite. Some users who ran the test reported
C# beating the straight C code. (though personally I don't see how that's
possible)

So before you start rewiring things, by all means head over to
http://sqlite.phxsoftware.com and let me have a look at your testing code.

Robert
 
Back
Top