C++ Smart Pointers: Types, Usage, and Practices

C++ Smart Pointers: Types, Usage, and Practices

In today’s article, we will revisit smart pointers in C++. In resource management in C++, manually using <span>new</span>/<span>delete</span> can easily lead to memory leaks, dangling pointers, and exception safety issues. The smart pointers introduced in C++11 encapsulate ordinary pointers with RAII (Resource Acquisition Is Initialization): automatically releasing resources when the object goes out of scope, … Read more

Comprehensive Analysis of C++ Smart Pointer shared_ptr: From Principles to Practical Guide

Comprehensive Analysis of C++ Smart Pointer shared_ptr: From Principles to Practical Guide

1. Overview and Core Features <span>std::shared_ptr</span> is a smart pointer introduced in the C++11 standard library that implements the concept of shared ownership and automatically manages dynamically allocated memory resources through a reference counting mechanism. Compared to traditional raw pointers, <span>shared_ptr</span> significantly reduces the risks of memory leaks and dangling pointers, making it an indispensable … Read more

A Review of C++ Smart Pointers: Types, Usage, and Practical Scenarios

A Review of C++ Smart Pointers: Types, Usage, and Practical Scenarios

👆Click the blue text "Linux Armory" at the top, and select "Add to Favorites" in the upper right corner to not miss out on great articles and see valuable content first. 👆FollowLinux Armory, to receive hardcore Linux learning materials and code. Today, let’s revisit smart pointers in C++. In C++ resource management, manually using <span>new</span>/<span>delete</span> … Read more

Essential C++ Knowledge for AI Deployment – Must-Know for Interviews (Part 2)

Essential C++ Knowledge for AI Deployment - Must-Know for Interviews (Part 2)

1. What is Memory Leak and Its Types What is Memory Leak? A memory leak refers to a situation where a program fails to release memory that is no longer in use after dynamically allocating it, due to negligence or errors. Memory leak does not mean that the memory physically disappears, but rather that the … Read more

11 Key C++ Concepts Explained

11 Key C++ Concepts Explained

Overview This article will answer the following related questions, covering basic C++ concepts: 1. What is the purpose of the const keyword? 2. What is the purpose of the static keyword? 3. What is the difference between new and malloc? 4. What is the purpose of volatile? 5. How is C++ memory partitioned? 6. What … Read more

Essential C++ Knowledge for AI Deployment – Must-Know for Interviews (Part 1)

Essential C++ Knowledge for AI Deployment - Must-Know for Interviews (Part 1)

AI Deployment – Essential C++ Knowledge – Must-Know for Interviews (Part 1), organized for easy reference and review. 1. <span><span>#include</span></span>: Double Quotes <span><span>" "</span></span> vs. Angle Brackets <span><span>< ></span></span> Conclusion First Header files within the project: Prefer using <span>"…"</span> System/installed third-party library header files: Use <span><…></span> Search Order (General Approach) <span>#include "name"</span> First, search in … Read more

The Distinction Between Intrusive and Non-Intrusive Smart Pointers in C++: A Deep Dive

The Distinction Between Intrusive and Non-Intrusive Smart Pointers in C++: A Deep Dive

The Distinction Between Intrusive and Non-Intrusive Smart Pointers in C++: A Deep Dive <span>std::shared_ptr</span> is not a silver bullet; uncovering the memory management tool for high-performance scenarios—intrusive pointers Introduction:<span>std::shared_ptr</span> and its “hidden costs” Hello, C++ developers. We all love <span>std::shared_ptr</span>, which elegantly solves the memory management problem of shared ownership through reference counting. When we … Read more

Zero-Copy Techniques in C++

Zero-Copy Techniques in C++

1. Core Concepts of Zero-Copy Technology in C++ Zero-copy is an important optimization technique aimed at reducing unnecessary data copying in memory, thereby improving program performance, reducing memory usage, and decreasing CPU consumption. In C++, zero-copy techniques are implemented in various ways, including reference semantics, view types, and move semantics. 2. Introduction to std::string_view std::string_view … Read more

Introduction to Smart Pointers in Rust

Introduction to Smart Pointers in Rust

Smart pointers are a very core and powerful concept in Rust, involving memory safety management, and are deeply related to Rust’s ownership system, concurrency, recursive data structures, and more. In summary: In Rust, smart pointers are “pointers with additional functionalities” used to manage data on the heap, automatically implementing features such as deallocation, sharing, and … Read more

C++ Programming Tips: Managing Resources with Smart Pointers

C++ Programming Tips: Managing Resources with Smart Pointers

Resources refer to entities that, once used, must be returned to the system. For example, dynamically allocated memory using “new” needs to be returned to the system with “delete”, as well as resources like bitmaps and brushes. 1. Disadvantages of Manual Resource Management Consider the following example: We “new” a resource and return it to … Read more