Question

I am working in a project that features several C++ and a few C# components. I am currently working on a new C# component that needs to share data with a C++ component (there may be more components accessing this in the future). All components are running in the same process. My current idea is to use an in-memory database, but I'm not sure whether it is possible.

SQLite is popular and available for both C++ and C# projects, and it has an in-memory feature. The question is if it is possible to access the same database from both components, can I for instance use a handle to the db (pointer) created in C++ in my C# project?

Was it helpful?

Solution

Yes, that would be possible. Of course, you'd need to share some data structures and handles (as you say). That way SQLite cannot detect any difference between managed code and native code. Therefore there can be no difference in behavior.

Maybe it is easier if you just use PInvoke or C++/CLI to exchange data structures. Spinning up a whole SQL database just for passing around data in-process seems wasteful.

OTHER TIPS

Yes you can. The sqlite database is in memory but it resides as a file on disk. When you close the database connection it is flushed on to the file on disk. So you can basically open the db connection in one component write and close the connection so that other components can read/write into db. Its just similar to how you operate of files except that it is managed in memory rather then on disk so bit faster than files. But if your intention is IPC between c++ and c# there are other better ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top