Rico's Nerd Cluster

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

C++ - [Compilation 2] Compiler Directives

Macros, Pragmas, Attributes

Introduction Compiler directives are instructions that are not part of C++ / C standards, but tell the compiler how to compile the code. They starts with # (pronounced as “hash”), and are handled ...

C++ - [Compilation 1] Compilation Model

Header Files, Translation Unit, One Definition Rule (ODR), Compiler Optimization, Compiler, ELF

Compilation Model Creating an executable from a single, small source file is conceptually straightforward: 1 source file -> file_to_binary -> executable However, when a project consists o...

C++ - ABI Compatibility

ABI Compatibility: Introduction and Motivating Example ABI stands for Application Binary Interface. Two versions of the same library might be API-Compatible (you can recompile your code), but they...

C++ - [Pointers - 1] - Raw Pointer

Raw Pointers, Array, Casting

Raw Pointers 🚀 Basics new and delete: If you use new, you must use delete — otherwise, memory leak! see code. new[]:size must be provided as part of the signatu...

C++ - Pimpl Idiom

Minimal Structure 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // header // Widget.hpp #pragma once #include <memory> class Widget { public: Widget(); ~Widget(); void doSomething...

C++ - [Pointers - 2] - Smart Pointers

unique_ptr, shared_ptr

Unique Pointer Basics 1 2 #include <memory> std::unique_ptr<int> ptr = std::make_unique<int>(1); Note that a unique_ptr is only 8 bytes on a 64 bit system, and it’s the s...

C++ - Streams

Stringstream, iostream, string

Streams fstream Open a file, then start appending to the file: 1 std::ofstream ofs(filename, std::ios::out | std::ios::app); How to add a custom print function? 1 2 3 4 5 inline std::...

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. Iterator Category Examples Supported Operations ...