Sign in to follow this  
DrEvil

Best way for dlls to share data?

Recommended Posts

DrEvil    1148
I'm wondering what a fast an reliable way for 2 independant dlls to share data. I've read a bit about pipes and memory mapped files but wanted to get some opinions. It should preferably be usable on windows and linux, though I don't might doing some specific coding for each if necessary. Essentially what I'm wanting to do is give dllA access to a potentially large block of contiguous memory that is managed by dllB. dllB is loaded and in-use by a game. One way would be to allow dllA to LoadLibrary and GetProcAddress of dllB and use some exported functions to access the memory. This may be the easiest to go with, but I'd still like opinions either way. Thanks in advance.

Share this post


Link to post
Share on other sites
d_emmanuel    271
As for Windows, I'd definitely go with memory mapped files to create a shared memory pool that can be used by the two dlls. If I understand your second solution, you're simply mapping the two dlls into the address space of the application. This is ok as long the dlls don't need cross process communication.

Share this post


Link to post
Share on other sites
d_emmanuel    271
To clarify my last resonse: you only need a shared memory pool (via memory mapped files) if you need the dlls to communicate between processes
(i.e. dllA is loaded by app A and the dllB is loaded by app B). If the dlls are loaded by the same app, then they already exist within the virtual address space of the application so nothing special needs to be done. To be on the safe side though, you should make sure that the dlls and app are using the same version of the C runtime library.

I recommened going to MSDN and doing a search for dlls and memory mapped files to get more details.

Share this post


Link to post
Share on other sites
KevinLee    127
It seams that both of this dlls are loaded into a same process. So, you can access whatever you want in one process memory space. Do you mean cross-process communication?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this