Thread: MS STL strikes again

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    MS STL strikes again

    I've been working on resource management again and found a problem related to debug new and std::map.

    This code:
    Code:
    _Nodeptr _Buynode(_Nodeptr _Larg, _Nodeptr _Parg,
      _Nodeptr _Rarg, const value_type& _Val, char _Carg)
      {	// allocate a node with pointers, value, and color
        _Nodeptr _Wherenode = this->_Alnod.allocate(1);
        _TRY_BEGIN
        new (_Wherenode) _Node(_Larg, _Parg, _Rarg, _Val, _Carg);
        _CATCH_ALL
        this->_Alnod.deallocate(_Wherenode, 1);
        _RERAISE;
        _CATCH_END
    return (_Wherenode);
    }
    Fails on the bolded line if you define new as debug new prior to including std::map. The placement form of new works fine with the normal new but fails on the debug new that tracks allocations and de-allocations.

    Nice eh.

    The sample for std::map in the help docs for MSVS will not compile if you are defining debug new prior to using std::map.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I was absolutely sure that #redefining keywords was actually undefined, but I can't find any clause saying so.

    However, I don't see how this could be avoided.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well it's not like I would be doing that for a release but it is nice for a debug build to track memory. That is unless you have a custom class that already does that for you which I don't. Without a redefine the debug CRT won't track allocations correctly. Every example I've seen on how to track allocations uses this method. Not sure if there is another way or not. You could overload new and delete globally however this still does not enable the nice featuers of the debug CRT. I've never had _CRTDBG_MAP_ALLOC work without the redefine.

    AFAIK STLPort does not suffer from this.
    Last edited by VirtualAce; 07-11-2008 at 05:01 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Speed test result
    By audinue in forum C Programming
    Replies: 4
    Last Post: 07-07-2008, 05:18 AM
  2. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  3. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  4. Ping
    By ZakkWylde969 in forum Tech Board
    Replies: 5
    Last Post: 09-23-2003, 12:28 PM
  5. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM