Uneven Work Distribution and Oversubscription

Wednesday, October 23, 2013

A few days ago I was teaching our Win32 Concurrent Programming course and showed students an experiment with the std::thread class introduced in C++ 11. The experiment is designed to demonstrate how to partition work across multiple threads and coordinate their execution, and the work to partition is simply counting the number of primes in a certain interval. You can find the whole benchmark here. The heart of the code is the parallelize_count function, below: void parallelize_count(unsigned nthreads, unsigned begin, unsigned end) {     std::vector<std::thread> threads;     unsigned...
no comments

Searching and Displaying C++ Heap Objects in WinDbg

Monday, August 5, 2013

This is something I am pretty excited to tell you about. But first, some motivation. In managed applications, there’s a huge number of tools and ways to inspect the managed heap contents. You can use a memory profiler to see references between objects and inspect individual objects. You can use WinDbg with the SOS extension to dump all objects of a particular type and execute additional scripts and commands for each object. You can even write C# code that uses the ClrMd library to parse heap contents and write your own diagnostic tools. C++ has nothing of...

Displaying and Searching std::map Contents in WinDbg

Thursday, July 25, 2013

This time we’re up for a bigger challenge. We want to automatically display and possibly search and filter std::map objects in WinDbg. The script for std::vectors was relatively easy because of the flat structure of the data in a vector; maps are more complex beasts. Specifically, an map in the Visual C++ STL is implemented as a red-black tree. Each tree node has three important pointers: _Left, _Right, and _Parent. Additionally, each node has a _Myval field that contains the std::pair with the key and value represented by the node. Iterating a tree structure requires recursion, and...
tags: , ,

Displaying and Searching std::vector Contents in WinDbg

Thursday, July 18, 2013

WinDbg has never been very good at visualization. While Visual Studio has always had autoexp.dat, and as of late also native debugger visualizers, WinDbg users had to settle for dumping memory areas and searching memory to identify patterns. On the other hand, Visual Studio does not offer any automation opportunities today if you’re looking to simplify your debugging process. You can’t write macros anymore as of Visual Studio 2012. WinDbg continues to offer scripting support so you can automate any mundane debugging tasks you encounter. If you make it past the initial learning curve and master WinDbg scripts,...
tags: , ,

Automatically Obtaining Source and Line Number from Symbol Name and Offset

Tuesday, June 25, 2013

Once upon a time, unmanaged code developers had to work very hard to correlate code offsets back to source file names and line numbers. One approach involved generating .cod files (assembly listings) for each module, and then painstakingly comparing the instruction offsets with the contents of the .cod file. For example, if you received a faulting stack trace from a client machine that had the frame BatteryMeter!TemperatureAndBatteryUpdaterThread+0xd0, you could go back to the .cod file for BatteryMeter.exe, look up the code listing for TemperatureAndBatteryUpdaterThread, and then look for the source line located at (or near) offset 0xd0. ...
one comment

Revisiting Value Types vs. Reference Types

Wednesday, April 10, 2013

Why do C#, the .NET Framework, and the CLR need value types and reference types? Why two categories of types? Why the added complexity in training developers to understand why and when to use each type of type? There are many answers, but very few get to the crux of the matter. You could try to justify the need for two types of types by looking at the semantic differences C# affords each. For example, you know that by default, instances of value types are copied when passed to a function, but instances of reference types are not -- only...

P/Invoke with C++ bool Return Values

Thursday, January 17, 2013

I encountered an interesting gotcha today, which I thought would be interesting to share with you. The symptoms were the following: I wrote a simple C++ function exported from a DLL, and tried to invoke it using a P/Invoke wrapper. The C++ function returns a bool, and was declared as follows (the code was simplified for expository purposes): extern "C" __declspec(dllexport) bool IsPrime(int n) {     if (n <= 1) return false;     if (n == 2) return true;     if (n % 2...
tags: ,

Runtime Representation of Generics—Part 1

Monday, August 27, 2012

This is an excerpt from Chapter 5 (Collections and Generics) of Pro .NET Performance, scheduled to appear in less than a month. I might be publishing a few more of these before and after the book is out. Before we can concern ourselves with the runtime implementation of generics, it’s paramount to ask whether there is a runtime representation of generics—as we will see shortly, C++ templates, a similar mechanism, have no runtime representation to speak of. This question is easily answered if you look at the wonders Reflection can do with generic types at runtime: Type...

New C++ Concurrency Static Analysis Warnings in Visual Studio 2012

Monday, July 2, 2012

Another cool feature in the Visual Studio 2012 C++ compiler is the revamped code analysis rule sets and brand new UI for configuring them. This is not just the simple /analyze switch we all know and love since Visual Studio 2005 anymore. To get a general impression of the UI changes, open a C++ project’s properties and check out the Code Analysis node. You’ll be able to review the rule set that runs on your project and optionally enable/disable specific warnings. Check out some of these rules: Specifically, I’d like to focus on the new...

Sessions From SELA C++ Conference: “The Style of C++ 11” and “The Future of C++”

Monday, June 18, 2012

Thanks for coming to my talks today at SELA’s C++ conference! It’s been a great audience and there was lots of interest in the new standard and what’s still coming ahead. There are still two more conference days ahead of us, and it’s great C++ born again! You can view my two talks below. The Style of C++ 11 The Future of C++ View more presentations from Sasha Goldshtein. I am posting short updates and links on Twitter as well as on this blog. You can follow me: @goldshtn
one comment