Implementing std::tuple From The Ground Up – Part 3: Constructing Tuples

January 23, 2015

In the previous installment we were finally able to define what tuple derives from. As a reminder, if we have a tuple of n elements, it (indirectly) derives from n instantiations of tuple_element. For example, tuple<int, string> indirectly derives from tuple_element<0, int> and tuple_element<1, string>. We'll need to add some operations to tuple_element to make it more useful. At the very least, we need to make it constructible from its value type: explicit tuple_element(T const& value) : value_(value) {} explicit tuple_element(T&& value) : value_(std::move(value)) {} Now let's start building some fundamental operations for our tuple class so that we can get busy constructing...
tags: ,
no comments

SDP Workshop: Monitoring .NET Performance with ETW

January 22, 2015

I've been doing .NET performance workshops at the SDP for 4 years now, and this year I thought it was time for a change. The traditional workshop used to be about a variety of commercial performance measurement tools, such as the Visual Studio profiler, and unfortunately I wasn't able to offer any labs, so it wasn't really a hands-on workshop. This time I decided to rewrite 90% of the materials and focus only on ETW tools. Here's the rough agenda of the workshop -- I'm pretty happy with the results! Introduction to semantic logging and ETW Capturing kernel ETW events with xperf...
no comments

Implementing std::tuple From The Ground Up – Part 2: Index Sequences

January 16, 2015

In the previous installment we had the following definition of tuple, and were looking for a way of improving it so that the caller doesn't have to provide the integer indices. template <size_t... Indices, typename... Types> class tuple : tuple_element<Indices, Types>... { }; tuple<0, 1, int, string> tup; Basically, we need to provide the indices ourselves. First, let's decouple the tuple class from the indices -- we don't want the client to see the additional template parameters required: template <size_t... Indices, typename... Types> struct tuple_impl : tuple_element<Indices, Types>... { }; template <typename... Types> class tuple : tuple_impl<???, Types...> { }; So... how is the tuple class going to provide tuple_impl with all the indices?...
tags: ,

Implementing std::tuple From The Ground Up – Part 1: Introduction and Basic Structure

January 12, 2015

std::tuple is a very nice facility originally introduced in C++ TR1. It is a heterogenous container of elements that has a statically known size. In C++ 11, std::tuple can be implemented using variadic templates; a single std::tuple class can support an arbitrary number of template type arguments. In this series of blog posts we will implement std::tuple from first principles. The purpose of this exercise is not to provide the best-performing or most-conformant tuple implementation, but rather to see what foundational concepts are required to implement it. NOTE: This blog series relies on good familiarity with variadic templates and basic...
tags: ,

SDP December 2014: State of the Platforms & Visual Studio Diagnostics Hub

December 31, 2014

It's been an incredibly busy month, preparing for my last conference of 2014 -- SELA Developer Practice. It's still ongoing, and we had to spill a few workshops to next week because registration numbers exceeded our expectations -- again. What a good problem to have. I've had the pleasure of delivering a keynote, a breakout session, and two workshops at the conference. Below are the materials for the shorter sessions. Thanks for coming, and one more thing: we're thinking about relocating the November 2015 conference to sunny Eilat. What do you think? Keynote: State of the Platforms Slides This is my usual update...
tags: ,
no comments

Diagnosing Native Memory Leaks with ETW and WPA

December 2, 2014

As a followup to my previous post on native memory leaks, here's a quick walkthrough for diagnosing memory leaks using Event Tracing for Windows. The process is fairly simple. The Windows heap manager is instrumented with ETW traces for each memory allocation and deallocation. If you capture those over a period of time (when your application is leaking memory), you can get a nice report of which blocks were allocated during the trace period and haven't been freed. If you also ask ETW to capture the call stack for allocation events, you can see where the application is allocating...
one comment

Native Memory Leak Diagnostics with Visual Studio 2015

December 1, 2014

The Current Landscape of Native Memory Diagnostics Leak diagnostics is a nasty business in native applications. There have been many attempts at solving this problem automatically. To name a few: The CRT Debug Heap (which is no longer used by default in Visual Studio 2015! - See update below.) can help identify memory leaks by associating each allocation with additional data on the allocating source file and line number. At program exit (or whenever a special CRT function is called), all blocks that haven't been freed are printed out. This has been around forever. The problem is that you need to...

Garbage Collection and .NET Debugging at Build Stuff

November 25, 2014

I spent most of last week at Build Stuff, a really cool software conference in Vilnius, Lithuania. The conference was great with a really exciting atmosphere: energized, passionate developers having conversations and playing table tennis in the hallways during the day, and drinking lots of beer in the evenings. Even the weather was quite nice -- there was only a little snow, and temperatures didn't drop below -1 Celsius, which means we could walk around the old town's historical landmarks; grab some sushi, ribs, and beer; and do some window shopping. So, a great success! I was invited to deliver...
no comments

A Loop of Nested Exceptions

November 17, 2014

It was a pretty incredible coincidence. Only a few days apart, I had to tackle two problems that had to do with nested exception handlers. Specifically, an infinite loop of nested exceptions that led to a stack overflow. And that's a pretty fatal combination. A stack overflow is an extremely nasty error to debug; a nested exception means the exception handler encountered an exception, which can't be pretty; and to add insult to injury, a stack corruption was also involved behind the scenes. Read on to learn some more about the trickiness of diagnosing nested exceptions and what can...

Making .NET Applications Faster: My Pluralsight Courses

November 14, 2014

I can't believe I waited until now to blog about it, but I have two courses on Pluralsight covering .NET performance optimization. If you've been reading this blog for any time now, you know this is one of my favorite topics -- and I was absolutely thrilled to join the Pluralsight author team in early 2014. My first course is titled Making .NET Applications Faster, and it was released in May. It's a fairly short course, running just under 2 hours, that covers the basics of .NET performance optimization. Some of my favorite topics include implementing value types correctly, using NGen...