There are 2 binary files. One of them is the native / unmanaged C ++ dll, while the other is controlled by C # exe. Now what I am doing is writing a function in a C ++ dll and allocating memory inside it using malloc. I exported this function to be used by my C # module.
In C ++, I did:
char* FunctionHavingAllocatedMemory(int i){
char* p = (char*)malloc(100);
.....
return p;
}
In C #, I did:
[DllImport("C++.dll")]
private static extern string FunctionHavingAllocatedMemory(int i);
Now, my question is: is there a need to free memory in the C ++ module, or does the C # module automatically free it when the function returns. Why I think, since C # is a managed module, it will automatically clear the memory.
( , ++, , ++. ).