Memory requirement in CListCtrl
-
The following is my code for the listctrl ///////////////////////////////////////////////////////////// lvItem.iImage = m_nIcon; for (int i = 0; i<200;i++) { nChk ++; szTest.Format("%d",nChk); m_test = szTest; UpdateData(FALSE); // Set up item lvItem.mask = LVIF_TEXT | LVIF_IMAGE; lvItem.iItem = 0; lvItem.iSubItem = 0; lvItem.pszText = LPTSTR(LPCTSTR(szTest)); m_List.InsertItem (&lvItem); // Set up time and date CString szTimeDate = timeTimeStamp.Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT); int nIndex = szTimeDate.Find(" "); CString szTime = szTimeDate.Right(szTimeDate.GetLength() - nIndex - 1); CString szDate = szTimeDate.Left(nIndex); nListCount = m_List.GetItemCount(); if(nListCount >1000) m_List.DeleteItem (nListCount-1); nListCount = m_List.GetItemCount(); // Insert Subitem in list control (date) lvItem.mask = LVIF_TEXT; lvItem.iSubItem = 1; // SubItem 1 is Date column lvItem.pszText = LPTSTR(LPCTSTR(szDate)); m_List.SetItem(&lvItem); // Insert Subitem in list control (time) lvItem.iSubItem = 2; // SubItem 2 is Time column lvItem.pszText = LPTSTR(LPCTSTR(szTime)); m_List.SetItem(&lvItem); } /////////////////////////////////////////////////////////// What I find is that the memory requirement increases as I increase the items but as u can see I am removing the items from the List after the max. no of items is reached still I find a large chunk of memory being taken up. The memory requirement for say 1000 items is 2964K then it should remain the same as I am deleting the extra items. How can I control this memory requirement.? Rohan
-
The following is my code for the listctrl ///////////////////////////////////////////////////////////// lvItem.iImage = m_nIcon; for (int i = 0; i<200;i++) { nChk ++; szTest.Format("%d",nChk); m_test = szTest; UpdateData(FALSE); // Set up item lvItem.mask = LVIF_TEXT | LVIF_IMAGE; lvItem.iItem = 0; lvItem.iSubItem = 0; lvItem.pszText = LPTSTR(LPCTSTR(szTest)); m_List.InsertItem (&lvItem); // Set up time and date CString szTimeDate = timeTimeStamp.Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT); int nIndex = szTimeDate.Find(" "); CString szTime = szTimeDate.Right(szTimeDate.GetLength() - nIndex - 1); CString szDate = szTimeDate.Left(nIndex); nListCount = m_List.GetItemCount(); if(nListCount >1000) m_List.DeleteItem (nListCount-1); nListCount = m_List.GetItemCount(); // Insert Subitem in list control (date) lvItem.mask = LVIF_TEXT; lvItem.iSubItem = 1; // SubItem 1 is Date column lvItem.pszText = LPTSTR(LPCTSTR(szDate)); m_List.SetItem(&lvItem); // Insert Subitem in list control (time) lvItem.iSubItem = 2; // SubItem 2 is Time column lvItem.pszText = LPTSTR(LPCTSTR(szTime)); m_List.SetItem(&lvItem); } /////////////////////////////////////////////////////////// What I find is that the memory requirement increases as I increase the items but as u can see I am removing the items from the List after the max. no of items is reached still I find a large chunk of memory being taken up. The memory requirement for say 1000 items is 2964K then it should remain the same as I am deleting the extra items. How can I control this memory requirement.? Rohan
Make a virtual list... NG
-
The following is my code for the listctrl ///////////////////////////////////////////////////////////// lvItem.iImage = m_nIcon; for (int i = 0; i<200;i++) { nChk ++; szTest.Format("%d",nChk); m_test = szTest; UpdateData(FALSE); // Set up item lvItem.mask = LVIF_TEXT | LVIF_IMAGE; lvItem.iItem = 0; lvItem.iSubItem = 0; lvItem.pszText = LPTSTR(LPCTSTR(szTest)); m_List.InsertItem (&lvItem); // Set up time and date CString szTimeDate = timeTimeStamp.Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT); int nIndex = szTimeDate.Find(" "); CString szTime = szTimeDate.Right(szTimeDate.GetLength() - nIndex - 1); CString szDate = szTimeDate.Left(nIndex); nListCount = m_List.GetItemCount(); if(nListCount >1000) m_List.DeleteItem (nListCount-1); nListCount = m_List.GetItemCount(); // Insert Subitem in list control (date) lvItem.mask = LVIF_TEXT; lvItem.iSubItem = 1; // SubItem 1 is Date column lvItem.pszText = LPTSTR(LPCTSTR(szDate)); m_List.SetItem(&lvItem); // Insert Subitem in list control (time) lvItem.iSubItem = 2; // SubItem 2 is Time column lvItem.pszText = LPTSTR(LPCTSTR(szTime)); m_List.SetItem(&lvItem); } /////////////////////////////////////////////////////////// What I find is that the memory requirement increases as I increase the items but as u can see I am removing the items from the List after the max. no of items is reached still I find a large chunk of memory being taken up. The memory requirement for say 1000 items is 2964K then it should remain the same as I am deleting the extra items. How can I control this memory requirement.? Rohan
You are assuming that deleting an item from a list control, or freeing memory in general, automatically lowers your application's memory footprint. That is wrong. While freed memory does eventually make its way back to the available pool, Task Manager will show you what is effectively a high-water mark. In other words, just because you do not see it go down does not necessarily mean there is a problem.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
You are assuming that deleting an item from a list control, or freeing memory in general, automatically lowers your application's memory footprint. That is wrong. While freed memory does eventually make its way back to the available pool, Task Manager will show you what is effectively a high-water mark. In other words, just because you do not see it go down does not necessarily mean there is a problem.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
How do I check that the memory requirement for the EXE is within permissible limits.Since the action atleast indicates an increase in memory usage by the EXE. As you say the Task Manager is not the true picture, but the memory usage shown in the same is certainly increasing.How do I solve that.
-
How do I check that the memory requirement for the EXE is within permissible limits.Since the action atleast indicates an increase in memory usage by the EXE. As you say the Task Manager is not the true picture, but the memory usage shown in the same is certainly increasing.How do I solve that.
I'm not exactly sure what you are asking, but it sounds like you need to run your program trhrough all of the possible combinations, and then note the memory consumption via Task Manager right before you shut it down. That might give you a good-enough answer to the question, "In the worst case, how much memory does my program require to run?"
"One must learn from the bite of the fire to leave it alone." - Native American Proverb