performance issue OF CArray

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

  1. rahulonly4u

    rahulonly4u New Member

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    Code:
    
    
    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;
    	}
    	else
    	{  
                 int i=0;
    	     char c; 
                 cout<<"Enter any Character To create Carray object \n\n";
    	     cin>>c;
    		     // 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";
    	    cin>>c;
    
               for(i=0;i<=10000;i++)
    		   {
    			   
    			   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";
               cin>>c;
    
                mycarray.RemoveAll();
                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";
                 cin>>c;
    		  // 
    		  //// 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";
              cin>>c;
          cin>>c;
    		  getchar();
          }
    
    	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
    Rahul
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    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

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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

    Joined:
    Sep 6, 2010
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    software developer
    Location:
    india
    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



    Regards
    Rahul
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice