Originally Posted by
CornedBee
Never free memory allocated in one module in a different module.
Three choices.
1) Pass in enough memory for the DLL to use, so that it doesn't have to allocate.
2) Create a DLL function that you pass the struct and it frees the memory.
3) Since this is C++, why not use a std::vector or a boost::multi_array instead of managing the memory yourself?
This is the headache I'm facing. I'm allocating memory in DLL and freeing it in the program that is using the DLL. So far, it works alright. I agree it is risky, but for your first suggestion, I can't do it because the memory is dynamic, I will never know the exact memory size needed.
For your second suggestion, it's not possible because the if I free the memory in DLL, then my main program can't receive the array from DLL
For you third suggestion, I think it will have the first problem as the second suggestion
Below is my code which I call the DLL. minemqb is the DLL function. I'm passing in a pointer chain_interact_result, which the function minemqb will point it to the results I needed
Code:
minemqb(&chain_interact_result, db, protein[protein_index].chain[chain1][0]+1, protein[protein_index].chain[chain2][0]+1, 0, 2, 0, 2, 0);