On Apr 4, 4:49 am, "Maxim Yegorushkin" <maxim.yegorush...@gmail.com>
wrote:
On 2 Apr, 08:36, "Le Chaud Lapin" <jaibudu...@gmail.com> wrote:
A while back I originated a post about a Virtual_Destructor<> wrapper
template whose purpose was simply to add a no-op virtual destructor to
a class. Using it. at least under Microsoft Windows, circumvents the
new/delete heap mismatch problem.
If I understand correctly, the problem stems from allocating *memory*
from one heap and returning it to another. The natural way to solve it
would be to allocate and deallocate memory from the same translation
unit, would not it?
You understanding is correct, and that is one way that programmers in
Windows often go about solving this problem. For every object
manufactured inside the DLL using the new operator, there will be
another function inside the DLL whose sole purpose is to call delete
against a pointer to such object. Then, within the EXE, whenever the
programmer needs to invoke delete operation against a pointer to
object manufactured in DLL, he first binds to the special deallocation
function inside the DLL, then invokes it, supplying pointer to the
object.
Those functions can be overloaded operator delete/new of that class.
intent. This solution has already been mention here. Is it not good
[ comp.lang.c++.moderated. First time posters: Do this! ]