using a p/invoke wrapper

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
 
R

Richard Grimes [MVP]

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
 
R

Robert Simpson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top