Pied Peter

まだらなるピータ

0%

SmartPointer: Case Study to Taste System Programming

Preface

System Programming is such a tough stuff to knock on its door — You have to get familiar with low-level details of bare metal, and then consider how to code for fine-grained modifications.

In 2022, I dedicate almost all of my spare time for system programming — to build a tiny database system with Rust based on LSM and raft paper, to dive into modern C++14 and inspire myself with many great ideas to design a system, even with borderless demon C++(if you try coding systems with C++, you know what I mean…). Anyway, even though I am a big fan of Rust, I still recommend you to push yourself coding systems with C++ when early stage. C++ could give you better senses of bare metal — just like pointer is an abstraction of memory, and Rust hides some details to make you focus on system design and implementation, which is really a good news for those veterans, like senior engineers, but as for beginners, details matter. Maybe C++’s nuanced bugs would suffer you, but some bug you fucked up makes you stronger — believe it.

In this Blog, I would code a tiny SmartPointer with modern C++ to give you a taste of system programming — with its design patterns and some basic ideas to balance performance and elegant implementation.

Source Code

Brief Review About SmartPointer

Implementations

Ideas

  1. Concern with code reusability, we choose to implement with Template Method and promise data mutuality with friend class.

  2. namespace features to unify library naming.

  3. Design UPtr class as basic data structure to count references.

Welcome to my other publishing channels