Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   performance issue OF CArray (http://www.go4expert.com/forums/performance-issue-carray-t23257/)

rahulonly4u 9Sep2010 12:13

performance issue OF CArray
Code: VC ++ visual studio 2005

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    int nRetCode = 0;

    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        // TODO: change error code to suit your needs
        _tprintf(_T("Fatal Error: MFC initialization failed\n"));
        nRetCode = 1;
             int i=0;
         char c;
             cout<<"Enter any Character To create Carray object \n\n";
             // see the memory usage in task manager
             CArray<CString,CString> mycarray;
            cout<<"after just creating Carray object ::"<< mycarray.GetSize()<<"\n";

                     // see the memory usage in task manager
            cout<<"Enter any Character To Add Elements to Carray object \n\n";

               mycarray.Add( _T("this is test"));
           cout<<"after adding elements to Carray:::" <<mycarray.GetSize() <<"\n \n";
                                    // see the memory usage in task manager
           cout<<"Enter any Character to remove elemnts from carray \n\n";

            cout<<"after Removing All elements to map:::" <<mycarray.GetSize() <<"\n \n";
           // see the memory usage in task manager
         cout<<"Enter any Character to use FreeExtra  \n\n";
          //// see the memory usage in task manager
    //       mycarray.FreeExtra();
    //       cout<<"after Feree Extra elements to map:::" <<mycarray.GetSize() <<"\n \n";
          cout<<" U    Can   Wait  For Some Time";
          cout<<" Too See the Effect Of freeExtra in Task Manager";
          cout<<"Enter any Character To exit From the Application \n\n";

    return nRetCode;

hi am using this code and confirming memory usage bye the process by TASK MANGER

which is as below

starting process-> 2492 KB

just After Creating Object -> 2544 KB

After adding Elements to carray -> 3620 KB

After Removing ele from Carray -> 2616 KB

why there is a Difference of 2616- 2544 =72 kB as i have deleted all elements from carray

and wonderfully some times it goes automatically to 90 /100 KB instead of 2492 KB (at the start of the process)

Please describe This behavior

With Regards

xpi0t0s 10Sep2010 11:56

Re: performance issue OF CArray
Probably Windows hasn't released all memory back to the OS and is keeping some of it just in case you do further memory allocations.

If you suspect a memory leak, run the above in an infinite loop and check if the process grows continuously until it crashes due to lack of memory. If it doesn't then there is no memory leak.

rahulonly4u 13Sep2010 12:15

Re: performance issue OF CArray
Thanks allot i apply this trick and i dint found much memory consumed by application and their is no error
"run out of memory" but i couldn't understand the behavior of "taskbar" i also find that when i run the above code and minimize the cmd line window task bar show strange result memory use by process reduced dramatically

xpi0t0s 13Sep2010 12:37

Re: performance issue OF CArray
1. Please use sentence structure. I haven't got a clue what you're talking about there.
2. "allot" is not the same as "a lot". "A lot" is two different words with a space between them.

rahulonly4u 14Sep2010 14:45

Re: performance issue OF CArray
Dear Sir ,

I am sorry for inconvenience , i have one little doubt to share please help me
I get Puzzled when i see the task manager when i run the above application and as i see the task bar
memory usage by application is around 2500k but as i minimize console window it reduces to 70-90 k
how minimizing of console window is affecting memory usage by application up to such extent and when i increase the no of elements added in " carray" this difference increases

please describe me the strange behavior of Task manager


All times are GMT +5.5. The time now is 00:13.