Memory Problem on CPtrArray
-
Hi all, Who had worked on Pocket PC please help me! I'm using CPtrArray to store a array of pointer(as below, it is pointer of CData class). + Firstly, I allocate memory for objects (using operator "new") , and add them to CPtrArray. + Then, I get these pointers and using "delete" operator to free allocated memory. However, even though I freed all allocated memory, but for the frist times of runing this source on Pocket PC, memory always increase. Of course, for next times of runing, memory is not changed. (I monitor memory by go to "Setting\Memory") Here is my source code: class CData { public: CData(); virtual ~CData(); private: wstring m_strFullName; wstring m_strNativePlace; wstring m_strDescription; int m_nAge; int m_nHeight; int m_nWeight; bool m_bSex. } CPtrArray lstData; CData * pData; int nSize = 10000; for (int i = 0; i < nSize; ++i) { lstData.Add(new CData()); } for (i = 0; i < nSize; ++i) { pData = (CData*)lstData.GetAt(i); delete pData;//free memory } lstData.RemoveAll(); lstData.FreeExtra(); Many thanks for your help.
-
Hi all, Who had worked on Pocket PC please help me! I'm using CPtrArray to store a array of pointer(as below, it is pointer of CData class). + Firstly, I allocate memory for objects (using operator "new") , and add them to CPtrArray. + Then, I get these pointers and using "delete" operator to free allocated memory. However, even though I freed all allocated memory, but for the frist times of runing this source on Pocket PC, memory always increase. Of course, for next times of runing, memory is not changed. (I monitor memory by go to "Setting\Memory") Here is my source code: class CData { public: CData(); virtual ~CData(); private: wstring m_strFullName; wstring m_strNativePlace; wstring m_strDescription; int m_nAge; int m_nHeight; int m_nWeight; bool m_bSex. } CPtrArray lstData; CData * pData; int nSize = 10000; for (int i = 0; i < nSize; ++i) { lstData.Add(new CData()); } for (i = 0; i < nSize; ++i) { pData = (CData*)lstData.GetAt(i); delete pData;//free memory } lstData.RemoveAll(); lstData.FreeExtra(); Many thanks for your help.
Your code appears to be fine. Maybe since your PocketPC application uses a certain 'maximum' amount of memory, that memory is now available and 'allocated' by the OS for use by your program from a pool. Within the 'pool' your application undergoes subsequent suballocations. You might need to see if the PocketPC API has some other type of memory compaction routine you need to call. Then you might see the memory footprint reduced.
-
Your code appears to be fine. Maybe since your PocketPC application uses a certain 'maximum' amount of memory, that memory is now available and 'allocated' by the OS for use by your program from a pool. Within the 'pool' your application undergoes subsequent suballocations. You might need to see if the PocketPC API has some other type of memory compaction routine you need to call. Then you might see the memory footprint reduced.
Thanks Blake Miller, I have just try your idea and You are correct! I created 2-buttons on a dialog. And on LButtonDown event of those buttons, I implemented as the same source code to allocate memory, add pointers to array and finally, free them. At first, I clicked mouse on Button 1, and of course, the memory was increased. But, I clicked mouse on Button 2 later, the memory was not changed. However, I have not found a API function as you suggested. My PDA configuration is "HP iPAQ hx2410". I'm a beginer of programing on PDA. please help me!
-
Thanks Blake Miller, I have just try your idea and You are correct! I created 2-buttons on a dialog. And on LButtonDown event of those buttons, I implemented as the same source code to allocate memory, add pointers to array and finally, free them. At first, I clicked mouse on Button 1, and of course, the memory was increased. But, I clicked mouse on Button 2 later, the memory was not changed. However, I have not found a API function as you suggested. My PDA configuration is "HP iPAQ hx2410". I'm a beginer of programing on PDA. please help me!
I have no idea if there is such a function, I just suspected that you had to look for one. Sometimes the memory management software on handhelds behaves this way.