Rico's Nerd Cluster

「离开世界之前 一切都是过程」

C++ - ABI (Application Binary Interface) Compatibility

Introduction and Motivating Example Two versions of the same library might be API-Compatible (you can recompile your code), but they are not ABI-compatible (you cannot just swap the binary .so wit...

C++ - chrono

Basic Timing: high-resolution clock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <chrono> void foo(){ auto start = std::chrono::high_resolution_clock::now(); std::cout<<"Hello...

C++ - Manual Memory Garbage Collector

Boehm-Demers-Weiser (BDW) Collector

Boehm-Demers-Weiser Collector (BDW) Collector BDW Collector is designed as a “drop-in” replacement in C for the default memory allocation functions (malloc, free, etc.). Developers can link agains...

C++ - Iterators

Basic Usage An iterator needs to be dereferenced *it or it->first so its internal data can be accessed. If you have an std::unordered_map<Key, Value> (or std::map<Key, Value>), its...

C++ - [OOP] Members

Member Attributes and Methods, Copy, Move

Member Attributes Let’s take a look at a tricky example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #include <iostream>...

C++ - [OOP] Polymorphism - Virtual Functions and Virtual Inheritance

Virtual is virtually complicated. Dynamic Dispatch, Dreadful Diamond Derivative (DDD) Problem ...

Introduction The virutal keyword is very versatile. A really short and nasty summary is, it is to ensure the correct functions or base class is inherited / loaded during runtime. Motivating Examp...

C++ - [OOP] Initialization

Default Initialization, Memory Order, Ctor for Inheritance, Parsing and Construction

Default Initialization Default Initialization is when a variable is initialized without explicit value. They could be in an uninitialized state and accessing them could be an undefined behavior. ...

C++ - Friends

Friend Class, Friend Function, Inner Class

In C++, friend functions and friend classes provide controlled access to private members of a class. While useful, they should be used judiciously to maintain encapsulation and avoid unnecessary de...

C++ - [Concurrency 3] Memory Model

Introduction The C++ memory model was formally introduced in C++11 mainly for multithreading. Before C++11: Threading was platform-dependent. (POSIX threads for Unit systems) Behavior of sh...

C++ - [Concurrency 2] Coroutine

Coroutine Coroutines in C++ allows us to write asynchronous code in a sequential style. It allows us to resume and suspend, instead of blocking a thread. A coroutine by default is single-threaded,...