1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

performance issue OF CArray

Discussion in 'C++' started by rahulonly4u, Sep 9, 2010.

  1. rahulonly4u

    rahulonly4u New Member

    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
  2. xpi0t0s

    xpi0t0s Mentor

    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.
  3. rahulonly4u

    rahulonly4u New Member

    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
  4. xpi0t0s

    xpi0t0s Mentor

    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.
  5. rahulonly4u

    rahulonly4u New Member

    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


Share This Page