Click here to Skip to main content
15,887,083 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: STL Deque Container - question Pin
Paul Ranson29-Apr-04 0:24
Paul Ranson29-Apr-04 0:24 
GeneralRe: STL Deque Container - question Pin
CoolVini29-Apr-04 4:31
CoolVini29-Apr-04 4:31 
GeneralRe: STL Deque Container - question Pin
Paul Ranson29-Apr-04 11:22
Paul Ranson29-Apr-04 11:22 
GeneralRe: STL Deque Container - question Pin
CoolVini29-Apr-04 22:34
CoolVini29-Apr-04 22:34 
GeneralHTML Dialog question ... Pin
Hadi Rezaee28-Apr-04 23:29
Hadi Rezaee28-Apr-04 23:29 
GeneralDll & Vectors Pin
Bernhard28-Apr-04 23:10
Bernhard28-Apr-04 23:10 
GeneralRe: Dll & Vectors Pin
Anonymous29-Apr-04 0:05
Anonymous29-Apr-04 0:05 
GeneralRe: Dll & Vectors Pin
Mike Dimmick29-Apr-04 0:21
Mike Dimmick29-Apr-04 0:21 
I suspect that one DLL is linked against the static version of the C run-time library, but the other, and the program, against the DLL version. The version that works is linked against the DLL; the one that doesn't is linked with a static version.

Each time the C run-time is initialised (at program startup and at DLL initialisation, it creates a new operating system heap with HeapCreate. All allocations through the C run-time's allocation functions (malloc, ::operator new, calloc, realloc, etc) ultimately come from this heap using HeapAlloc/HeapRealloc - and all the deallocation functions pass this heap's handle to HeapFree.

Aside: on NT 4 and older, and on Win9x systems, the CRT manages small blocks of memory from a single OS heap allocation because the OS heap wasn't very efficient with small blocks on those operating systems. This was improved with Windows 2000 and the CRT uses the OS heap directly for all allocations on these systems.

If you're using the Debug version of the C run-time, when you free memory (which the destructor of vector does for you, using the allocator type parameter's deallocate function) the run-time checks that you passed a valid pointer using the _CrtIsValidHeapPointer function. It considers it invalid if HeapValidate returns FALSE, which will happen if the pointer came from a different heap.

Since you're passing an empty vector into the function, an allocation happens within the DLL, from the heap used by that DLL. The DLL version of the CRT will set up a single heap shared by all binaries using the DLL version, but each binary linked to the static CRT will have its own heap. The vector (assuming it's a local variable in the calling function) is destroyed at the end of the calling function, so deallocate gets called, which uses ::operator delete against the heap used by the executable. This is the wrong heap, so you get the assertion.

The fix is simple. All DLLs in the same process must link against the same C run-time DLL (a mixed process of some binaries linked with msvcrt.dll from VC 6 and some linked with msvcr70.dll or msvcr71.dll from VS.NET 2002 or 2003 will have similar problems). The alternative is to ensure that all allocations and deallocations happen within a particular DLL, and that objects never cross the boundaries.

Stability. What an interesting concept. -- Chris Maunder
GeneralRe: Dll & Vectors Pin
Antony M Kancidrowski29-Apr-04 3:20
Antony M Kancidrowski29-Apr-04 3:20 
GeneralProblem choosing collection… Pin
anderslundsgard28-Apr-04 22:53
anderslundsgard28-Apr-04 22:53 
GeneralRe: Problem choosing collection… Pin
David Crow29-Apr-04 2:13
David Crow29-Apr-04 2:13 
GeneralChildFrame and Menu Pin
amit_k_gupta28-Apr-04 22:52
amit_k_gupta28-Apr-04 22:52 
GeneralRound dialog drawing question Pin
YaronNir28-Apr-04 22:45
YaronNir28-Apr-04 22:45 
GeneralRe: Round dialog drawing question Pin
ohadp28-Apr-04 23:52
ohadp28-Apr-04 23:52 
GeneralRe: Round dialog drawing question Pin
YaronNir29-Apr-04 0:25
YaronNir29-Apr-04 0:25 
Questiongenerate c++ doc ? Pin
anderslundsgard28-Apr-04 22:25
anderslundsgard28-Apr-04 22:25 
AnswerRe: generate c++ doc ? Pin
Anonymous28-Apr-04 22:51
Anonymous28-Apr-04 22:51 
GeneralRe: generate c++ doc ? Pin
anderslundsgard28-Apr-04 22:55
anderslundsgard28-Apr-04 22:55 
AnswerRe: generate c++ doc ? Pin
Anonymous29-Apr-04 0:03
Anonymous29-Apr-04 0:03 
AnswerRe: generate c++ doc ? Pin
Pedro Ruiz29-Apr-04 0:31
Pedro Ruiz29-Apr-04 0:31 
GeneralClickety police ! Pin
Trollslayer29-Apr-04 1:03
mentorTrollslayer29-Apr-04 1:03 
GeneralWebBrowser Pin
Gem128-Apr-04 21:30
Gem128-Apr-04 21:30 
QuestionUsing CSplitterWindow with MFC? Pin
Roozbeh6928-Apr-04 21:26
professionalRoozbeh6928-Apr-04 21:26 
GeneralPdh API - CPU Counter returns 99 Pin
willy_23x28-Apr-04 20:53
willy_23x28-Apr-04 20:53 
GeneralRe: Pdh API - CPU Counter returns 99 Pin
David Crow29-Apr-04 2:19
David Crow29-Apr-04 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.