Category Archives: VC++

Checking Memory Corruption with _CrtCheckMemory – From the Debugger

Edit: In VS2015+ versions this trick is still useful but is a bit different.

Posted in Debugging, VC++, Visual Studio | 2 Comments

/d1reportAllClassLayout – Dumping Object Memory Layout

Roman just posted a nice investigation he did, mostly using the g++ switch -fdump-class-hierarchy – which dumps to stdout a graphical representation of generated classes layout. VC++ has no official similar switch, but deep inside  its undocumented pile of goodies … Continue reading

Posted in Debugging, VC++ | 3 Comments

fflush Fails to Switch From Read to Write on Files fopen’ed with ‘r+’ Access

The fopen documentation states: When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be … Continue reading

Posted in VC++ | 2 Comments

std::vector of Aligned Elements – Revisited

A while ago I posted about vector::resize – how it takes a parameter by value and thus cannot store aligned elements. I confessed I didn’t understand Stephen Lavavej’s words: …There’s a reason that our resize() is currently taking T by … Continue reading

Posted in VC++ | 1 Comment

PGO and OpenMP

Alan Ning just posted about a cool hack of VS’s PGO switch, which was a sad reminder of all the wonderful goodies I’d never taste in my present job. PGO builds can incorporate many optimizations that regular builds cannot, thereby … Continue reading

Posted in VC++ | Leave a comment

On _purecall and the Overhead(s) of Virtual Functions

A while ago a friend asked me whether pure virtual functions have higher overhead than regular virtual functions. At the time I answered that this cannot be – the pure/non-pure distinction is meaningful only at compile time, and non-existent at … Continue reading

Posted in VC++ | 4 Comments

Setting Breakpoints on All Class Methods

In a recent video John Robbins (probably the world’s leading debugging expert) made a public request of his audience: write a VS addin that enables setting function breakpoints by partial name matches. That is, let the user type C*::M* in … Continue reading

Posted in Debugging, VC++, Visual Studio | 2 Comments

std::vector of Aligned Elements

Update: answers to some questions raised below are available in a newer post. Fact (1): Functions cannot accept aligned types by value. That is really a fact of nature, but it can make sense:  the function’s stack frame can be … Continue reading

Posted in VC++ | 12 Comments

Playing With Strings

Take the following code: What would you see when watching the resulting strings? Probably not what you expect: This is a simplified version of a much dirtier, very real bug I dealt with recently. Several string and debugger features joined … Continue reading

Posted in VC++, Visual Studio | 6 Comments

Debug/Release Numerical Differences

We recently had trouble reproducing in debug builds the exact numerical behavior of release builds.   This just happens  occasionally, and we’re used to accept it as some compiler black magic.  This time we dug a bit deeper – I’m pretty … Continue reading

Posted in Debugging, VC++ | 4 Comments