Category Archives: C++

Condition variables performance of boost, Win32, and the C++11 standard library

About four years ago, I wrote the condition variables in Win32 API was much faster than boost threading library implementation. Since then the boost threading library has been rewritten and C++11 has introduced the threading support in the standard library. … Continue reading

Posted in C++, Optimization | Tagged , , | 1 Comment

Windows thread pool keeps threads even after being closed

Windows Thread pool maintains threads so that it doesn’t have to create a new one when a work item is submitted. It may surprise you that it maintains threads even after you close the thread pool with CloseThreadpool() API function. … Continue reading

Posted in Advanced Debugging, C++ | Tagged , | 1 Comment

std::unique_ptr for Windows handles

To close a Windows handle with std::unique_ptr, we need to define a type with operator() and specify it as the second template parameter. This is different from std::shared_ptr where we can just specify the functor in a constructor parameter. Although … Continue reading

Posted in C++ | Tagged , | 4 Comments

Base64 encoder (C++)

Base64 encoder is used to convert any binary data into “printable” character sequence so that it can be carried over textual protocols such as XML. Here is a simple function to get base64 text out of byte buffer based on … Continue reading

Posted in Algorithm, C++ | Tagged | 1 Comment

How does boost::phoenix work?

The boost::phoenix is simply mysterious – it doesn’t look like C++. for_each(v.begin(), v.end(), if_(arg1 > 5) [ cout << arg1 << ", " ] ); It’s the standard std::for_each. The third parameter is usually a functor but boost::phoenix lets you … Continue reading

Posted in C++ | Leave a comment

std::string in VC++ may store a short string in a stack

The std::string object can store any length of string. However, it does not mean it always allocate char array on the heap. If you look into the type definition of std::string in VC++ 8.0, it has interesting array called _Bx::_Buf. … Continue reading

Posted in C++ | Leave a comment

Asynchronous Exception Handling

In Windows, you can catch an asynchronous exception (such as an access violation exception) with catch(…) clause. struct Foo {  ~Foo(){    // destructor  }}; try{   Foo foo;   *reinterpret_cast<char*>(0) = 0;}catch(…){    // handle access violation.} However, the behavior differs depends on … Continue reading

Posted in C++ | Leave a comment