RE: [GD-Windows] new/delete across DLL's
Brought to you by:
vexxed72
From: Jon W. <hp...@mi...> - 2003-03-24 18:21:08
|
Welcome to DLL hell. There are two kinds of DLL hell: the Unix hell, where some library can=20 decide to replace malloc() in the global symbol table, and suddenly=20 you're running with some other allocator than you tested your code=20 with; and the Windows hell, where each DLL can run with its own=20 allocator (say, debug vs release vs version 7.0), which means that you=20 have to balance all allocations and deletions. The only sane way around this that I've found is to base your cross- DLL object model on factory functions and abstract interfaces, and use=20 "deleteYourself()" as a virtual function to delete an instance (or go=20 all the way and acquire()/release() with ref counting). You may note that COM does a lot of these things, btw :-) Also, for the same reasons, inline functions are often a very bad idea=20 for objects that are supposed to live in DLLs. First, because you have=20 to re-compile the user when you change the implementation of the object=20 (so you can't rev the DLL separately unless you take a LOT of care).=20 Second, because if you happen to allocate memory, then the inline may=20 live in one of many different modules. This is especially bad with STL=20 style containers. Cheers, / h+ > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On Behalf Of > Ben Hawes > Sent: Monday, March 24, 2003 9:08 AM > To: gam...@li... > Subject: [GD-Windows] new/delete across DLL's >=20 >=20 > Am I doing something wrong, or is this correct behaviour: >=20 > in core.dll I have a class CFooBar. >=20 > in the game exe, I call wibble =3D new CFooBar; > Later on, within the exe, I call delete wibble; and get an Assert=20 > warning because I'm deallocating from the wrong heap. >=20 > This seems very strange, that I can only deallocate a class=20 > defined in a DLL from within that DLL, even if the instance was=20 > allocated somewhere else. Am I understanding this correctly, or=20 > am I doing something else to cause the problem? Is there any way=20 > round this? >=20 > [ cruise / casual-tempest.net / transference.org ] >=20 >=20 >=20 > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_idU5 >=20 |