Flow
I have a reader DLL written in C++
.
I also have writer DLL written in some language (not in C++
).
DLLs run in the same process synchronously.
- Reader DLL calls writer's DLL API,
GetData
- Writer DLL prepares data, either by downloading it, extracting it, etc.
- Reader DLL reads and use the data
Question
What is the recommended way for DLLs to share data?
Approach 1
Reader DLL pass file path argument to Writer DLL and reads the data from file.
Cons
I'd like to avoid writing data to disk. Even if it is the most robust solution I'd like to explore different options since it doesn't seem very elegant to me to write data to disk when you don't need it on disk.
Approach 2
Writer DLL will allocate buffer on the heap and return an address and size to the reader DLL.
Cons
Reader DLL must free the memory. Is it feasible? delete memory by address and size?
Also, it is probably a big NO-NO allocating and freeing buffer across modules/languages
Approach 3
Separate the GetData() to two calls.
- Reader DLL Calls GetDataSize()
- Reader DLL allocate buffer and pass the address to Writer DLL
- Writer DLL fills buffer
- Reader DLL use buffer
- Reader DLL frees buffer
This is the acceptable WINAPI approach.
Cons
I assume that Writer DLL is capable of knowing the size of the data prior to writing but that is not always the case.
Approach 4
Use windows file mapping
Cons
Similar cons to Approach 2 & 3.
- Who will create the file mapping?
- Who will unmap?
- File mapping has no dynamic size. You must define the size when creating it.