0%

This is my learning notes from the course - Mastering C++ Standard Library Features.

Rule of Five and Rule of Zero

  • How to make sure that your classes properly expose move operations
  • Rule of three (before C++11)
  • Rule of five and rule of zero (C++11 and later)

Rule of Three

  • Before C++11, the rule of three claims that:
    • If you have a class explicitly defining one of the following:
      • Destructor
      • Copy constructor
      • Copy assignment operator
    • Then, it should probably define all three
  • This prevents mistake and oversights when implementing classes that manage resources
    Read more »

Setup a New Laptop

I always want to have the same work environment/setup on my desktop/laptop. Here’s just a quick notes for what I usually need on my work station.

Read more »

Using Open VM Tools

Open VM Tools (open-vm-tools) is the open source implementation of VMware Tools for Linux guest operating systems.

The open-vm-tools-desktop package includes additional user programs and libraries to improve the interactive functionality of desktop operations of your virtual machines. The package enables you to resize a guest display to match its host console window or the VMware Remote Console Window for vSphere. The package also allows you to copy and paste between host and guest OSes, as well as to drag and drop between guests and a host for the VMware Workstation and VMware Fusion products.

Read more »

This is my learning notes from the course - Mastering C++ Standard Library Features.

Creating Movable Classes

  • Why your classes should be movable
  • Emplacement
  • How to write classes that benefit from movable semantics
  • The “rule of five“ and “rule of zero
  • Example: Implementing barebones movable and move-aware std::vector

Standard Library Support for Movable Types

  • The benefits of making your classes move-aware
  • Standard Library utilities that work with move-aware user-defined types

Why Movable Types?

  • Writing classes that support move operations can greatly increase performance, safety, and expressiveness of your code
  • The Standard Library provides many utilities that make use of move semantics where possible, even for user-defined types

Almost every container in the Standard Library is “move-aware“. This means that it will use move operations (if available) when dealing with its items.

Let’s begin by looking at std::vector.

Assuming that foo is a class that supports move semantics, we can see that vector will try to move whenever possible.

Read more »

This is my learning notes from the course - Mastering C++ Standard Library Features.

Smart Pointers Guidelines

  • How to write robust, safe, and efficient code that uses smart pointers
  • How to return/pass smart pointers from/to functions
  • The role of raw pointers in Modern C++
  • How to choose between raw/unique/shared pointers
  • Data structure and argument passing code examples

No Allocation is Better than Allocation

  • Making use of the stack and value semantic types should be preferred to dynamic allocation
  • Objects on the stack are easier to reason about and more *”predictable”*
  • Dynamic memory usage can have a significant cost: allocations are not free, they can reduce cache locality, and the compiler is often note able to aggressively optimize
  • Sometimes allocations are necessary - allocate only when you need to
  • Always use smart pointers - do not use new/delete
    Read more »