°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°° Memory control and debugging tools °°°°°°°°°°°°°°°°°° °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° Memory errors are the most unpleasant. Debugger, IDE and program itself works in this situation in the same manner. They hang up the computer. KNOW-HOW contain the solution of this problem, really - two solutions. First is the HCHECK.CPP (heap check) file. It works using #pragma directive, and does not require any modifications in your program. If you include it to project, it works, if not - it does not. After program termination this code outputs heap info: Þ before: 6200, after: 1500 This mean, that you have forget to call some destructor, free some memory close graphics or do something like that. "before" MUST be equial to "after". Þ heapcheck: -1 This line reports that you have destroy your heap, for example, call the destructor two times for the same structure. heapcheck MUST be 2. Second tool is much more powerfull. It is FARHEAPD.LIB file (source codes included). To use it, for example, from IDE, you should include it to project, compile the program with debug information, then go to DOS Shell (Alt-F, D), switch on the printer, and type in DOS prompt line: Þ >set debug=prn Þ >program name The program will work in the usual manner, but printer will print all memory allocations, deallocations and results of these operations. Usint this listing you could find line, where result become <> exept of <>. °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° Taking into account that program could be extremely large, and listing - too, I include additional tool to interprete this listing (MINFO.EXE). Instead of endless listing like ....... debugging C memory management: malloc 7EA3:0004 for 80 bytes debugging C memory management: malloc 7EA9:0004 for 80 bytes debugging C memory management: malloc 7EAF:0004 for 4096 bytes debugging C memory management: malloc 7FB0:0004 for 38 bytes debugging C memory management: malloc 7FB3:0004 for 15 bytes debugging C memory management: malloc 7FB5:0004 for 512 bytes debugging C memory management: free 7FB5:0004 debugging C memory management: malloc 7FB5:0004 for 51 bytes debugging C memory management: malloc 7FB9:0004 for 1 bytes debugging C memory management: malloc 7FBA:0004 for 74 bytes .......... (total 1 Mbyte ) user get: Level 1 >( 440) WARNING! Free without Malloc at pointer 0000:0000 Level 1 >( 441) WARNING! Free without Malloc at pointer 0000:0000 Level 1 >( 442) WARNING! Free without Malloc at pointer 0000:0000 Level 1 >( 443) WARNING! Free without Malloc at pointer 0000:0000 (total 4 lines)