Archived

This topic is now archived and is closed to further replies.

_ASSERTE(_CrtCheckMemory());

This topic is 5146 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

_CrtCheckMemory() fails I think at the termination process of my programme. it makes an "unhandled exception". it happened after I ported my application from vc6 to vc7. do anyone know what may cause such a thing? it''s written in help file: _CrtCheckMemory Confirms the integrity of the memory blocks allocated in the debug heap (debug version only). int _CrtCheckMemory( void ); Return Value If successful, _CrtCheckMemory returns TRUE; otherwise, the function returns FALSE. Remarks The _CrtCheckMemory function validates memory allocated by the debug heap manager by verifying the underlying base heap and inspecting every memory block. If an error or memory inconsistency is encountered in the underlying base heap, the debug header information, or the overwrite buffers, _CrtCheckMemory generates a debug report with information describing the error condition. When _DEBUG is not defined, calls to _CrtCheckMemory are removed during preprocessing. but I still have no idea what may cause this error? what should I look for? serdar

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Use the debugger, maybe deleting something twice? maybe deleting something that should be deleted.

Share this post


Link to post
Share on other sites
I''ve seen this bug a few times. In my case, the cause was usually one of two things...

Writing past the end of an array
Resizing an stl object in a different dll to the one it was created in.

Share this post


Link to post
Share on other sites
quote:
Original post by CoderTCD
quote:
Original post by Sandman
Writing past the end of an array
created in.


what does it mean I didn't understand.



I'm not sure which bit you didn't understand, so I'll explain both of them.

Writing past the end of an array: If you have an array of 7 elements and you write to the 8th element, that's writing past the end. e.g


char* text = new char[7];
strcpy(text,"This string is way too big to fit in the array");

delete [] text;


The second one (passing stl objects over a dll interface) is really just a case of trying to delete memory which doesn't belong to you. An executable maintains a separate heap space to it's client dlls, so if you try and call delete on memory which was allocated with new in a different dll, you'll get this error.
In the case of STL being the culprit, you can define a custom allocator which uses the win32 memory allocation functions (HeapAlloc() etc) which solves the problem, or you can just avoid passing STL objects over the dll interface altogether


[edited by - Sandman on November 13, 2003 11:19:18 AM]

Share this post


Link to post
Share on other sites