DLL on Win NT vs. Win 95 
Author Message
 DLL on Win NT vs. Win 95

Gregor:

I'm getting the same message when I create a DLL that implements a C++
class and then I use new and delete in the main program to reference it.
I'm not actually doing the malloc and free in different modules in that
case, since presumably 'new' and 'delete' are just calling them at some
point from the main module.  If I find out anything else I'll let you
know...

--Tully



Quote:
>   The second change concerns memory allocation from a DLL:
> _CrtIsValidHeapPtr() now asserts whenever I free a pointer
> in a DLL other than the one that allocated it (the DLLs
> statically link the C run-time lib). This was no problem
> under Win95 and no crashes or memory leaks result on WinNT
> 4.0 if I ignore the assertion, but I assume that I have a
> problem here. Is there a standard policy to handle this?
> Obviously I should free() my heap pointers in the DLL that
> malloc()'d them, but is there some elegant scheme to do
> this? Since I'm providing a DLL-based class library, the
> user would have to explicitly "reattach" any storage allocated
> by the lib. This seems kind of tedious. Any suggestions?
> How does MFC solve this?



Mon, 31 May 1999 03:00:00 GMT  
 DLL on Win NT vs. Win 95

Gregor--
 I discovered that the when I compiled the DLL that contained my class
without debug--the assertion went away.  I would have expected that if I
compiled the main module without debug (but I can leave it on there).
Wild--
--Tully



Quote:
>   The second change concerns memory allocation from a DLL:
> _CrtIsValidHeapPtr() now asserts whenever I free a pointer
> in a DLL other than the one that allocated it (the DLLs
> statically link the C run-time lib). This was no problem
> under Win95 and no crashes or memory leaks result on WinNT
> 4.0 if I ignore the assertion, but I assume that I have a
> problem here. Is there a standard policy to handle this?
> Obviously I should free() my heap pointers in the DLL that
> malloc()'d them, but is there some elegant scheme to do
> this? Since I'm providing a DLL-based class library, the
> user would have to explicitly "reattach" any storage allocated
> by the lib. This seems kind of tedious. Any suggestions?
> How does MFC solve this?



Mon, 31 May 1999 03:00:00 GMT  
 DLL on Win NT vs. Win 95

Quote:

> ...

>   The second change concerns memory allocation from a DLL:
> _CrtIsValidHeapPtr() now asserts whenever I free a pointer
> in a DLL other than the one that allocated it (the DLLs
> statically link the C run-time lib). This was no problem
> under Win95 and no crashes or memory leaks result on WinNT
> 4.0 if I ignore the assertion, but I assume that I have a
> problem here. Is there a standard policy to handle this?
> Obviously I should free() my heap pointers in the DLL that
> malloc()'d them, but is there some elegant scheme to do
> this? Since I'm providing a DLL-based class library, the
> user would have to explicitly "reattach" any storage allocated
> by the lib. This seems kind of tedious. Any suggestions?
> How does MFC solve this?

I have been experiencing similar problems. If ignoring the assertion
works will rebuilding the C run-time library with the offending call
commented out fix the problem ?

This is obviously not an ideal solution.




Mon, 31 May 1999 03:00:00 GMT  
 DLL on Win NT vs. Win 95

Well if you compile in RELEASE mode the assert won't be there so there
is no problem.  However the assert means something is _WRONG_ in your
code and needs to be fixed.  In the original post the problem is that
he was statically linking to the runtime, and allocating memory in
one module (DLL) and  freeing it in another.  This won't work since
each module has its own copy of the C runtime, and each runtime has its
own unique heap.  SO the problem is he was trying to free memory which
wasn't allocated in the heap trying to do the freeing.  There are two
solutions

1 - Use the DLL version of the C runtime
2 - Use the API HeapAlloc/HeapFree functions instead of malloc/free
--
Isn't it a bit unnerving that doctors call what they do "practice"?



Mon, 31 May 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. DLL on Win NT vs. Win 95

2. Win NT vs. Win 95

3. Win NT vs Win 95/98

4. Win 95/95 to Win NT

5. Win NT to Win 95

6. Porting application from Win 95 to Win NT

7. Q: Differences WIN NT / WIN 95 in VC++ 5.0

8. Registry - Win 95/Win NT

9. Win NT to Win 95

10. Win NT 4.0 - Win 95 Registry Reading Problems

11. Win 95 -> Win NT

12. Dialog behaviour in Win 95 and Win NT

 

 
Powered by phpBB® Forum Software