_tests/fsMemMgr/main.cpp

00001 
00002 //---------------------------------------------------------------------------
00003 // Please run this example from the development environment to see a proper
00004 // code position in case a RUNTIME BREAK occurs.
00005 //---------------------------------------------------------------------------
00006 // Turn on the memory tracking & the wrapping macros (which provide detailed
00007 // code position information). It should be included as the first header in
00008 // a common configuration header.
00009 #include <fs/sys/fsMemMgr.h>
00010 //---------------------------------------------------------------------------
00011 // Most of headers (those that doesn't collide with the 'new' and 'delete'
00012 // wrapping macros can be included freely).
00013 // ... here come headers mentioned above ...
00014 #include <stdio.h>
00015 //---------------------------------------------------------------------------
00016 // If the headers collide, the wrapping 'new' and 'delete' macros have to be
00017 // disabled temporarily (note that this technique in not limited to header
00018 // including).
00019 #include <fs/sys/fsMemMgr_NoT.h> // turn off the tracking macros
00020 // ... here come guarded headers...
00021 #include <vector>
00022 #include <fs/sys/fsMemMgr.h> // turn on the tracking macros
00023 //---------------------------------------------------------------------------
00024 void SomeFunc()
00025 {
00026     std::vector<int *> Leak3;
00027     Leak3.push_back(new int);
00028     Leak3.push_back(new int);
00029 }
00030 //---------------------------------------------------------------------------
00031 int main()
00032 {
00033     // optional - affects the name of the log file
00034     fs::sys::mmgr::SetModNm("main");
00035 
00036     int *pLeak1 = new int;
00037     char *pLeak2 = new char[128];
00038     
00039     SomeFunc();  
00040  
00041     // UNKNOWN / BAD MEMORY ADDRESS => MEMORY MANAGER RUNTIME BREAK
00042     // <uncomment below to see>
00043     // int *pBadPtr = pLeak1 + 1;
00044     // delete pBadPtr;
00045     
00046     // WRONG DEALLOCATION METHOD => MEMORY MANAGER RUNTIME BREAK
00047     // <uncomment below to see>
00048     // delete pLeak2;
00049     
00050     // ....
00051     // MEMORY LEAKS DETECTED => MEMORY MANAGER RUNTIME BREAK
00052     
00053     return 0;
00054 }
00055 //---------------------------------------------------------------------------
00056 // +--------------------------------------------+
00057 // | FipS' MEMORY MANAGER (basic stats)         |
00058 // | module: main                               |
00059 // +--------------------------------+-----------+
00060 // |    Total number of allocations | 6         |
00061 // |  Total number of deallocations | 2         |
00062 // |      Max number of allocations | 6         |
00063 // |                Number of leaks | 4       ! |
00064 // +--------------------------------+-----------+
00065 
00066 // +------------------------------------------+
00067 // | FipS' MEMORY MANAGER (tracking details)  |
00068 // | module: main                             |
00069 // +------------------------------+-----------+
00070 // |    Max allocated memory size | 152 B     |
00071 // |              Number of leaks | 4       ! |
00072 // +------------------------------+--+--------+---------------------------------+------------+-----------+
00073 // | ...\fs\_tests\fsmemmgr\main.cpp | 36     | main                            | 0x00356180 | 4 B       |
00074 // | ...\fs\_tests\fsmemmgr\main.cpp | 37     | main                            | 0x00356260 | 128 B     |
00075 // | ...\fs\_tests\fsmemmgr\main.cpp | 27     | SomeFunc                        | 0x003563c0 | 4 B       |
00076 // | ...\fs\_tests\fsmemmgr\main.cpp | 28     | SomeFunc                        | 0x00356580 | 4 B       |
00077 // +---------------------------------+--------+---------------------------------+------------+-----------+

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]