RSSAmplifier

Blog

Shahar Mike's Web Spot

Recent content on Shahar Mike's Web Spot

shaharmike.comRSS feed ↗15 posts

Latest posts

How We Optimized Dragonfly to Get 30x Throughput with BullMQ

It’s been a while since I added any new content here. Sorry about that! However, in case you’ve been following along, I just posted a new blog post on my (new) company’s blog. I hope you’ll find it interesting! It’s title is How We Optimized Dragonfly to Get 30x Throughput with BullMQ , and it tells the story of how we went about optimizing our service to get >30x…

Longest C++ Variable Declaration

Here’s a challenge: what’s the longest variable declaration you can come up with? That’s not useful in any way. Quite the opposite - the result is something you’d never want to see in your codebase. But it’s an interesting mental challenge, or at least so I think. Ground rules: Each keyword used gets you 1 point, repetitions allowed; Must be global variable; Must be…

Compiling Clang from Scratch

In this post I’ll show how easy it is to build clang from scratch on Linux, and how to use it both directly and with CMake. But Why? Clang is changing rapidly, and new features are added frequently. On the other hand, Linux distros have ancient versions shipped with them. That’s just frustrating. Furthermore, building Clang is so easy that it really shouldn’t be a blocker for you…

Move Semantics

Move Semantics are a C++11 feature which complements C++98’s RVO ; Think of them as user-defined RVO-like optimization . While originally designed to only allow optimizations, one can also utilize move semantics to limit APIs. This is how std::unique_ptr is able to be a move-only type, allowing it to enforce single ownership (more about std::unique_ptr here ). Motivation As we saw…

Dollhouse

As our oldest daughter was nearing her 4th birthday, my wife and I considered to give her a dollhouse. Very soon after we decided to build her one instead of purchasing. Tools Used We have a wood workshop at work. It’s sort of an employee benefit, rather than something that’s really work-related. Awesome, I know. It also has a great view :) So most of the tools I used aren’t…

Free Cloud VM & HTTPS

If your knowledge of what it takes to have an SSL encrypted website (aka https ) is as outdated as mine was a couple of weeks ago - you will find this quick post useful. A colleague of mine recently mentioned the fact that you can get SSL certificate for any website for free. I know that issuing certificates was every CA’s business model for ages, and so I was very surprised to learn that.…

Return Value Optimization

Return Value Optimization (RVO), Named RVO (NRVO) and Copy-Elision are in C++ since C++98. In this post I will explain what these concepts mean and how they help improve runtime performance. I will use our old friend Snitch - a class dedicated to printing at key events: struct Snitch { // Note: All methods have side effects Snitch() { cout << "c'tor" << endl; } ~Snitch() { cout << "d'tor" << endl;…

Using libclang to Parse C&#43;&#43; (aka libclang 101)

In this post I&rsquo;ll provide a quick tutorial for using libclang. I started playing around with libclang while implementing Reflang &ndash; an open source reflection framework for C++. Then I came to appreciate the amazing work done by its developers. Please note that we will start with a program and will gradually add code. Scroll to the end of the post to view the complete solution. libclang?…

Exploring std::shared_ptr

Today we&rsquo;ll talk about C++&rsquo;s built-in smart pointer std::shared_ptr . If you have not yet read my previous post about std::unique_ptr I would highly recommend doing so before continuing. std::shared_ptr shared_ptr is another C++11 managed pointer. Like unique_ptr , it also saves you the need to call new and delete (and to generally worry about forgetting to release etc). Unlike…

Exploring std::unique_ptr

Today we&rsquo;ll talk about C++&rsquo;s built-in smart pointer std::unique_ptr , which is an extremely powerful, simple & common tool. std::unique_ptr C++98 had std::auto_ptr . It&rsquo;s problematic in areas I do not wish to discuss here, and so it was deprecated and replaced by the awesome unique_ptr . unique_ptr is a simple &lsquo;smart&rsquo; pointer: it holds an instance of an object and…

Exploring std::string

Every C++ developer knows that std::string represents a sequence of characters in memory. It manages its own memory, and is very intuitive to use. Today we&rsquo;ll explore std::string as defined by the C++ Standard, and also by looking at 4 major implementations. Quick note : in this post I use the notation of compilers to inspect implementations. This is technically incorrect, as a Standard…

Template SFINAE & type-traits

Today&rsquo;s post is about template SFINAE & type-traits - cool C++ features with great compile-time power. Template SFINAE SFINAE is a scary-looking C++ acronym, which joins a long list of hard-to-remember capital-letter concepts (such as RAII, RVO, RTTI, PIMPL, etc). SFINAE stands for &ldquo;Substitution Failure In Not An Error&rdquo;. Simply put, it means that when a compiler fails to…

UserData class

Many libraries provide their users with a way to add user-defined content to the library&rsquo;s objects. This is especially true for libraries in the graphics domain. Examples: Win32&rsquo;s SetWindowLongPtr() : allows setting void* on an HWND ; OGRE3d&rsquo;s UserObjectBindings : allows setting Any (similar to boost::any ) and also map strings to Any on various objects; Cocos2d-x&rsquo;s…

Naive std::function implementation

After exploring std::function in a previous post, I thought that it might be a good practice to implement a simple (and partial) std::function . It turned out to be much less code than I anticipated. I hope you&rsquo;ll like it. Features While std::function has a few typedef s and methods , the core functionality is assignment and invocation: Assignment through operator= Invocation through…

C&#43;&#43; vtables - Part 4 - Compiler-Generated Code

So far in this mini-series we learned how the vtables and typeinfo records are placed in our binaries and how the compiler uses them. Now we&rsquo;ll understand some of the work the compiler does for us automatically. Constructors For any class&rsquo;s constructor the following code is generated: Call parent(s) constructors if there are any; Set vtable pointer(s) if there are any; Initialize…