In connection with this issue ...
I wondered how to actually work with the memory in the DLL, and, in particular, what remains with the dynamic memory after the release of the DLL.
I created a simple DLL, in it the function make_array , which creates an array in dynamic memory. VC ++, static linking.
Then scoff like this:
dll = LoadLibrary("Dll.dll"); memfunc m = (memfunc)GetProcAddress(dll,"make_array"); int * a = m(5); for(int i = 0; i < 5; ++i) cout << a[i] << " "; cout << endl; FreeLibrary(dll); for(int i = 0; i < 5; ++i) cout << (a[i] *= a[i]) << " "; cout << endl; dll = LoadLibrary("Dll.dll"); m = (memfunc)GetProcAddress(dll,"make_array"); for(int i = 0; i < 5; ++i) cout << (a[i] *= a[i]) << " "; cout << endl; delete[] a; a = m(6); for(int i = 0; i < 5; ++i) cout << a[i] << " "; cout << endl; Well, i.e. I checked whether it is possible to delete memory in the program, and whether the memory remains available after the DLL is unloaded. So, if created by one compiler, then everything is normal, is the memory manager smart enough?
I did the same with Open Watcom - the result is the same.
But if the DLL is from OW, and the program is from VC ++, then everything works except delete[] . As, by itself, and was to be expected - due to different memory controllers.
No, I understand that where the memory is allocated - there and release :)
But I just can not answer two questions.
If the memory is allocated by the memory manager in the DLL, then what mechanism is used so that the two dispatchers do not quarrel? For the controller in the DLL is allocated some kind of memory? but when unloading a DLL, as I understand it, this area is not freed?
How to really work with things like smart pointers? Type, in DLL, call make_shared , the result of which is then used in the program - how to guarantee the last deletion in the DLL? All that comes up - too artificial. Unless to cause from the DLL?
PS Well, I did not work seriously with the DLL, I did not dig deep ...