-
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.
-
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.
-
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.