Author Archives: Ofek Shilon

Every Time You Try to Micro-Reuse Code, God Kills a Kitten.

– where by ‘macro-reuse’ I mean reusing objects or libraries (which is good), and by ‘micro-reuse’ I mean seeing a class that has some overlap with your needs and saying ‘hey, let’s derive from that and just override these two … Continue reading

Posted in Design | 2 Comments

Debugging Memory Leaks, part 3.5: Hacks with Hooks

Alan rightfully comments that setting a conditional breakpoint at _heap_alloc_dbg  significantly slows down the application. If run time is an issue for you even in debug builds and re-compilation is not an issue, here’s an alternative trick: use an allocation … Continue reading

Posted in Debugging, VC++ | 1 Comment

Debugging Memory Leaks, Part 3: Breaking on Allocations of Given Size

When battling memory leaks, you often start from the output of _CrtMemDumpAllObjectsSince or _CrtDumpMemoryLeaks (called for you if you use MFC) – something similar to: C:\myfile.cpp(20): {130} normal block at 0x00780E80, 68 bytes long. Data: < > CD CD CD … Continue reading

Posted in Debugging, VC++ | 3 Comments

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

Ternary Operator and Type Compatibility

The (?,:) operator, as in – is commonly referred to as the Ternary Operator. (It is a common abuse of terminology: a ternary operator is one that operates on three arguments. This particular ternary operator is the Conditional Expression operator.)  … Continue reading

Posted in C++ | 4 Comments

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