Size of a Empty Class with Virtual Function?

What is the size of the below class? struct MyClass { virtual ~MyClass(); }; The answer is size of a pointer(4 bytes or 8 bytes depending on the platform). That pointer is a vptr to vtbl of virtual functions. That being said, it is not a good idea to initialize a class consisting of POD …

Avoid False Sharing With C++11 alignas Keyword

When two threads are frequently accessing and updating the 2 different but independent variables on the same cacheline, cache thrashing occurs as a result because when the thread updates its variable, the thread on another CPU core has its cacheline invalidated and have to fetch from the main memory again even though it is not …

Making HTTP REST Request in C++ With WinHTTP

WinHTTP Wrapper The example code is hosted at Github. The WinHTTP Wrapper consists of one main class that is HttpRequest class. In its constructor, the following parameters: user_agent, proxy_username, proxy_password, server_username and server_password are optional. When accessing the website through a proxy that needs logon, pass in the proxy_username, proxy_password to the constructor. Sometimes, the …

C++: Faster to Retrieve Data By Ref Parameter or Returning a Ref?

In C++, there are two options to retrieve data from a object: either passing a reference parameter to be filled up or returning a reference. The former is making a copy of data (which may be what the developer wants) while the latter is returning a memory address of the data. The example code is …

Direct2D Tutorial Part 4: Gradient Brush

Table of Contents Introduction Linear Gradient Rainbow Linear Gradient Rainbow Linear Gradient Text Radial Gradient Radial Gradient Text Demo Code History Articles in the Series The example code is hosted at Github. Introduction In this article, we'll look at how to draw with linear and radial gradient colors in Direct2D. The prerequisite of the article …

Direct2D Tutorial Part 3: Affine Transforms

    Table of Content Introduction Text Format Translation Skew Rotation Scale The example code is hosted at Github. Introduction In this article, we'll look at how to do affine transform using matrices in Direct2D. The transformation has to be set up before any drawing that is to be transformed. The prerequisite of the article …

Direct2D Tutorial Part 2: Basic Shapes

Table of Content Introduction Stroke Style Solid Color Brush Line Rectangle Rounded Rectangle Triangle Circle The example code is hosted at Github. Introduction In this article, we'll look at how to draw lines and basic shapes in Direct2D. The prerequisite of the article is the knowledge to set up the RenderTarget. If you haven't got …

Optimizations That You Have to Wring From WebAssembly

Introduction First of all, I want to put up a disclaimer: I am not a WebAsssembly expert. All the 5 tips mentioned in this article are gained from my C++ OpenGL slideshow application. I have to admit I have no working knowledge on Blazor, an implementation of Webassembly for C# and .NET. And I am …