January 2015

Providing Explicit Specializations for Non-Template Members of Class Template -- Pavel Frolov

One of the lesser-known features of C++ templates.

Providing Explicit Specializations for Non-Template Members of Class Template

by Pavel Frolov

From the article:

C++ is full of surprises (albeit not always good ones grin. It is a well known fact that you can provide explicit specializations for function templates and class templates. But it was a total surprise to me, that you can provide explicit specializations for non-template members of class template without specializing the class template itself!

C++11 library components to make a programming scientist happy

A new video from Meeting C++ 2014:

C++11 library components to make a programming scientist happy

by Peter Gottschling

From the talk description:

This talk presents a survey over components of the C++11
standard library which facilitate the life of a programming scientist.
It will provide a gentle introduction to the random number generator
and evolve this to a complete application: the stochastic simulation
of share price development.

Type safe handles in C++--Emil Ernerfeldt

Some time ago, Emil Ernerfeldt wrote about type safe handles. Simple and interesting.

Type safe handles in C++

by Emil Ernerfeldt

From the article:

Let's say you have a system of resources and you identify them using integers as handles. These integers are meaningless to the user, but internally they may be indices into an array, or just a running count...

Why does a single integer assignment statement consume all of my CPU? -- Raymond Chen

A fresh here's-the-code-spot-the-performance-problem analysis.

Why does a single integer assignment statement consume all of my CPU?

by Raymond Chen

From the article:

Profiling showed that over 80% of the time spent by Calculate­The­Value was inside the Set­Int32 method call, in particular on the line

  *reinterpret_cast<int32_t *>(m_data) = value;

Why does it take so much time to store an integer to memory, dwarfing the actual computation to calculate that integer?

Spoiler hint: [Chaotic neutral]

Stroustrup speaking in India: 'No programming language is perfect' -- Ashwin Khan

stroustrup-pune.PNGCoverage of a stop on Bjarne Stroustrup's January world tour, from our Indian correspondent:

'No programming language is perfect'

By Ashwin Khan

From the article:

Renowned Danish computer scientist Bjarne Stroustrup, inventor of the widely used programming language C++, spoke engagingly about his creation to a packed audience of over 700 people at Dewang Mehta Auditorium, Persistent Systems on Thursday night. The event was attended by mostly IT professionals and students, who flocked to hear Stroustrup speak about how C++ has evolved and the future of programming...

Operator Overloading -- Arne Mertz

Arne Mertz describes in a series of articles the principles of operator overloading.

Operator Overloading

Operator Overloading: Common Practice

by Arne Mertz

From the articles:

Operators can be used to make user defined classes act like known types, e.g. like numbers, pointers and iterators. That way they facilitate the usage of those classes. They can also be used to make your objects do whatever you want them to do, for example build structures that save the operations for later evaluation. The latter is especially useful for building embedded DSLs and gives enough subject matter for a whole series of blog posts. [The first] post will cover the former use of operator overloading, i.e. writing operators that behave like “normal” operators.

... In [the second] post I will go into the details and write a bit about each operator and how a straight forward implementation might look if the operator is meant to work similar to built in operators.

 

The Rule of Zero -- Glennan Carnie

A complementary guideline to help to simplify the application code, without risking resource management issues.

The Rule of Zero

In a previous article – "The Rule of the Big Four (and a half)" we looked at resource management policies in C++.

Resource management is the general term for using the mechanisms in C++ to ensure that resources – files, dynamic memory, sockets, mutexes, etc – have their lifetimes automatically controlled so as to prevent resource leaks, deadlocks, etc. C++ refers to these mechanisms as RAII/RDID ( “Resource Acquisition Is Initialisation / Resource Destruction is Deletion”)

In this article we’ll have a look at a complementary guideline to help simplify your application code, without risking resource management issues – The Rule of Zero.

If you’re not familiar with the concepts of resource management I’d highly recommend having a look at the whitepaper before reading on.

Deleaker For Free For OpenSource Project Owners

[From time to time vendors use Suggest an Article to submit blog suggestions, like this one. We felt this would be of interest to readers. --Ed.]

 

Free License Offer

We've decided to offer Deleaker for free for all who has open source projects and want to fix leaks in the code fast. We just ask to mention Deleaker. That's all.

To get a license please contact us.

What is Deleaker?

Deleaker is a tool for Visual C++ developers to find memory leaks, GDI leaks, COM / OLE leaks, handle leaks and other leak types.

In the past Deleaker was available as extension for Visual Studio 2005, 2008, 2010, 2012 and 2013. Unfortunately it made Deleaker unavailable for those who uses Express Edition as Express Edition doesn't support extensions.

We have just released new build 3.0.27 that includes standalone edition of Deleaker.

How does Deleaker work?

Deleaker is based on hooks. For each allocation and deallocation it saves stack traces and one a user click to Take snapshot it shows all allocations that are not freed yet.

Deleaker is available as Visual Studio extension and as a standalone tool.

Just a few screenshots. Extension mode:

Standalone edition of Deleaker: