Exploring C++ Friend Functions

Exploring C++ Friend Functions

What is a Friend? A friend declaration appears within a class and grants a function or another class access to the private and protected members of the class that declares the friend (https://en.cppreference.com/w/cpp/language/friend.html). Points to note: Friend declarations are made within the class, but their specific location is not restricted and is not subject to … Read more

Singleton Pattern in Embedded C: Writing ‘Globally Unique’ More Stably

In embedded projects, some resources are inherently unique: watchdog timers, RTCs, system clocks, debug serial ports, loggers, system configuration managers, CRC modules… If these modules are carelessly piled up with global variables, issues such as initialization order chaos, difficult-to-trace write access, and ISR/task concurrency collisions will inevitably arise. The goal of the singleton pattern is … Read more

Singleton Pattern: The Guardian of Global State Consistency in Embedded Systems

Singleton Pattern: The Guardian of Global State Consistency in Embedded Systems

Follow our official account to keep receiving embedded knowledge without interruption! 1. Singleton Pattern The Singleton Pattern ensures that a class has only one instance and provides a global access point to that instance. The core structure diagram of the Singleton Pattern: [Image][Image][Image][Image][Image][Image] The structure typically includes: a private static instance (…

Exploring Static Variables in C++11 Lazy Singleton Pattern

Exploring Static Variables in C++11 Lazy Singleton Pattern

The singleton pattern in C++11 is one of the best practices we are familiar with. It utilizes the characteristics of static variables to safely implement lazy initialization, thread safety, and automatic memory management with very concise code. The implementation of the lazy singleton pattern in C++11 is roughly as follows: #include <iostream> class Singleton { … Read more

Singleton Pattern in C++

Singleton Pattern in C++

In programming, we sometimes use the singleton pattern:It aims to ensure that a class has only one instance and provides a global access point to that instance. This pattern involves a single class that is responsible for creating its own objects while ensuring that only a single object is created.Common applications of the singleton pattern … Read more

Detailed Explanation of the Singleton Pattern in Python

Detailed Explanation of the Singleton Pattern in Python

Background Have you heard of the Singleton Pattern in Python? I encountered it while reading someone else’s code and didn’t understand what that piece of code meant. Later, when I searched for information, I learned that the purpose of that code is to create a single instance. It was from that moment that I became … Read more

Kernel C++ Member Function and C Interface Adaptation Technology from an Assembly Language Perspective

Kernel C++ Member Function and C Interface Adaptation Technology from an Assembly Language Perspective

Fundamental Differences Between Member Functions and C Functions From an assembly perspective, the essential difference between member functions and ordinary C functions lies in the implicit <span>this</span> pointer passing: ; Ordinary C function call push param2 ; Parameter 2 push param1 ; Parameter 1 call CFunction ; Direct call add rsp, 10h ; Clean up … Read more

Singleton Pattern: The Guardian of Global State Consistency in Embedded Systems

Singleton Pattern: The Guardian of Global State Consistency in Embedded Systems

1. Singleton Pattern The Singleton Pattern ensures that a class has only one instance and provides a global access point. Core structure diagram of the Singleton Pattern: The structure typically includes: A private static instance (pointer to itself) A private constructor (to prevent external instantiation) A public static method (to get the unique instance) In … Read more

Design and Implementation of Singleton Pattern in C Language

Design and Implementation of Singleton Pattern in C Language

Design and Implementation of Singleton Pattern in C Language The Singleton Pattern is a commonly used software design pattern that ensures a class has only one instance and provides a global access point to that instance. Implementing the Singleton Pattern in C is relatively complex because C is a procedural programming language and does not … Read more