Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory Problem on CPtrArray

Memory Problem on CPtrArray

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresperformancelearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nobitact
    wrote on last edited by
    #1

    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.

    B 1 Reply Last reply
    0
    • N Nobitact

      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.

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • B Blake Miller

        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.

        N Offline
        N Offline
        Nobitact
        wrote on last edited by
        #3

        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!

        B 1 Reply Last reply
        0
        • N Nobitact

          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!

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups