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. Other Discussions
  3. IT & Infrastructure
  4. MFC CMap Problems

MFC CMap Problems

Scheduled Pinned Locked Moved IT & Infrastructure
c++performancehelpquestionlearning
4 Posts 3 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.
  • B Offline
    B Offline
    BarryPearlman
    wrote on last edited by
    #1

    :confused:I am stumped by the following. My application uses a lot of CMap's, about a dozen or so so far to store pointers, strings etc. I just tried to add the following: ----------------------------------------------------------- Test.h class CCMyClass : public CWnd { protected: DECLARE_MESSAGE_MAP() public: CCMyClass(); virtual ~CCApp_Menu(); typedef CMap, mapTest; protected: mapTest* p_Map; In the implementation, it is the standard yada, yada that Developer Studio put in then you add a class. In the constructor, we have: CMap p_Map = new mapTest; The next thing that it does is basically as follows: p_struct = new MyStruct; //MyStruct defined elsewhere .... Add data to structure here and store in map. p_Map->SetAt(n, p_struct); After I map a bunch of p_structs's, it then gets interesting. When I go to iterate the map at a later time: ......... POSITION pos = p_Map->GetStartPosition(); int nCount() = p_Map->GetCount(); // nCount is Correct //pos = 0xffffff!! Which is of course a problem! It is failing in afxtempl.h at: template AFX_INLINE POSITION CMap::GetStartPosition() const { return (m_nCount == 0) ? NULL : BEFORE_START_POSITION; } I have tried to create the map in other classes, some which have CMap's like the above that work correctly, however I get the same result. Everything else works fine. Other info: Developer Studio 7.0 Windows XP Dual AMD processors 1 Gb. RAM All current updates. No memory leaks? It is almost as if Windows will only allow a given amount of CMap's at any given time. Is that true? Has anyone else run into this? Work around? Any input is appreciated! Barry Barry

    P 1 Reply Last reply
    0
    • B BarryPearlman

      :confused:I am stumped by the following. My application uses a lot of CMap's, about a dozen or so so far to store pointers, strings etc. I just tried to add the following: ----------------------------------------------------------- Test.h class CCMyClass : public CWnd { protected: DECLARE_MESSAGE_MAP() public: CCMyClass(); virtual ~CCApp_Menu(); typedef CMap, mapTest; protected: mapTest* p_Map; In the implementation, it is the standard yada, yada that Developer Studio put in then you add a class. In the constructor, we have: CMap p_Map = new mapTest; The next thing that it does is basically as follows: p_struct = new MyStruct; //MyStruct defined elsewhere .... Add data to structure here and store in map. p_Map->SetAt(n, p_struct); After I map a bunch of p_structs's, it then gets interesting. When I go to iterate the map at a later time: ......... POSITION pos = p_Map->GetStartPosition(); int nCount() = p_Map->GetCount(); // nCount is Correct //pos = 0xffffff!! Which is of course a problem! It is failing in afxtempl.h at: template AFX_INLINE POSITION CMap::GetStartPosition() const { return (m_nCount == 0) ? NULL : BEFORE_START_POSITION; } I have tried to create the map in other classes, some which have CMap's like the above that work correctly, however I get the same result. Everything else works fine. Other info: Developer Studio 7.0 Windows XP Dual AMD processors 1 Gb. RAM All current updates. No memory leaks? It is almost as if Windows will only allow a given amount of CMap's at any given time. Is that true? Has anyone else run into this? Work around? Any input is appreciated! Barry Barry

      P Offline
      P Offline
      prcarp
      wrote on last edited by
      #2

      I use the CMap in a very similar fashion without problems. I did not copy your code to see what may be giving you the problem but thought I'd throw out my two cents: Change your code in the constructor from: CMap p_Map = new mapTest; to: mapTest *p_Map = new mapTest; You may have already done that but if not, it may be worth a shot. My CMap(s) are built with VC6, Win2k.

      B 1 Reply Last reply
      0
      • P prcarp

        I use the CMap in a very similar fashion without problems. I did not copy your code to see what may be giving you the problem but thought I'd throw out my two cents: Change your code in the constructor from: CMap p_Map = new mapTest; to: mapTest *p_Map = new mapTest; You may have already done that but if not, it may be worth a shot. My CMap(s) are built with VC6, Win2k.

        B Offline
        B Offline
        BarryPearlman
        wrote on last edited by
        #3

        2¢ is appreciated. The code I put in the thread was generic at best. The actual code declares the pointer and creates the object just as you suggested. It should have read: CMap< .......... >* p_Map = new mapTest; I do find it interesting that some people declare pointers as Class *pointer = and some as Class* pPointer. I use the second syntax, as that was the way I was taught. Actually, both work out to the same thing. Thanks again Barry

        K 1 Reply Last reply
        0
        • B BarryPearlman

          2¢ is appreciated. The code I put in the thread was generic at best. The actual code declares the pointer and creates the object just as you suggested. It should have read: CMap< .......... >* p_Map = new mapTest; I do find it interesting that some people declare pointers as Class *pointer = and some as Class* pPointer. I use the second syntax, as that was the way I was taught. Actually, both work out to the same thing. Thanks again Barry

          K Offline
          K Offline
          Kevin McFarlane
          wrote on last edited by
          #4

          BarryPearlman wrote: I do find it interesting that some people declare pointers as Class *pointer = and some as Class* pPointer. I use the second syntax, as that was the way I was taught. Actually, both work out to the same thing. I also use the second syntax. Recommended idiom in a C++ context is to use the second way. I also find it easier to read, especially when it comes to declaring reference arguments. However, it's not a big deal and I think it's not something that's pushed in style guides. Kevin

          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