A king's time, I learned the smart pointer in c + + (including code implementation)
catalogue
1. What is a memory leak
2. How to avoid memory leakage
3. Why is there a smart pointer
4. Use and principle of intelligent pointer
4.1RAII
4.2 classes designed with RAII idea
4.3 implementation of intelligent pointer
5. Summary
1. What is a memory leak
1. Memory leak: memory leak refers to the situation th ...
Posted by kjelle392 on Sat, 05 Mar 2022 16:50:49 +0100
Protocol Buffer Foundation: C++
Original address: https://developers.google.com/protocol-buffers/docs/cpptutorial
This article briefly introduces how to use protocol buffer in C + + through an example. You can learn:
How to work in the The message format is defined in the proto file;How to use the protocol buffer compiler;How to use the C++ protocol buffer interface to re ...
Posted by g00bster on Sat, 05 Mar 2022 15:55:55 +0100
Summary of top ten sorting algorithms
Top ten sorting algorithms
Common sorting algorithms include bubble sort, selection sort, insertion sort, merge sort, quick sort, Hill sort, heap sort, count sort, bucket sort and cardinal sort
Bubble sorting
When adjacent elements are equal, they do not exchange positions, so bubble sorting is a stable sorting.
void bubbleSort(vector ...
Posted by anujgarg on Sat, 05 Mar 2022 15:10:00 +0100
Section 9 of C + + - map / set (usage + underlying principle + simulation implementation)
With the foundation of the red and black trees in front, our task in this section is relatively easy.
Let's explain what Map and Set are with the help of network literature.
First of all, we need to know that the bottom layers of Map and Set are red and black trees.
It is a balanced binary search tree, that is, binary balanced search tree.
...
Posted by astricks on Sat, 05 Mar 2022 14:30:08 +0100
Static member variables, member functions and ordinary member variables, memory relationship of member functions, this pointer, constant functions and constant objects
Five memory areas of C + +
The memory pattern of C + + programs is usually divided into five areas: global data area, code area, stack area, heap area (i.e. free storage area) and constant area.Global data area (static area): store global variables, static data and constants;Code area: store the codes of all class member functions and non memb ...
Posted by The.Pr0fess0r on Sat, 05 Mar 2022 13:53:58 +0100
[Apollo 6.0] how does the cyber rt use the Reader to read the data sent by the Writer (top-level logic)
How does the Reader read the data of the Writer (top-level logic)
Generally, the reader is created with a Node. For example, in the Component class (the Component can process up to four message types at the same time. Here we will choose one data type to explain):
reader = node_->CreateReader<M0>(reader_cfg)
Therefore, we ca ...
Posted by ben2005 on Sat, 05 Mar 2022 12:39:47 +0100
STL roaming vector
std::vector source code analysis
Observe the STL design from the perspective of source code, and the code is implemented as libstdc++(GCC 4.8.5)
Because we only focus on the implementation of vector, and the implementation of vector is almost all in the header file, we can use such a method to obtain relatively fresh source code
// main.cpp
#in ...
Posted by Davo on Sat, 05 Mar 2022 11:14:05 +0100
Process / process classification / interprocess communication -- signal
process
Create process
Create a process and directly call the fork function:
#include <unistd.h>
pid_t fork(void);
Negative value: failed to create child process. 0: return to the newly created child process. Positive: returns to the father or caller. This value contains the process ID of the newly created child process.
#incl ...
Posted by nac20 on Sat, 05 Mar 2022 09:34:12 +0100
C++11 uses variable parameters in function templates and class templates
reference
1,http://c.biancheng.net/view/vip_8692.html
The so-called variable parameter means that the number and type of parameters can be arbitrary.
For function parameters, C + + always supports setting variable parameters for functions. The most typical representative is the printf() function. Its syntax format is:
int printf ( const cha ...
Posted by malcolmboston on Sat, 05 Mar 2022 07:55:00 +0100
PAT grade B experience (under update)
1002 write this number
c + + number and string conversion
Method 1: use stringstream: add header file #include
Number to string #include <string>
#include <sstream>
int main(){
double a = 123.32;
string res;
stringstream ss; //Define stream ss
ss << a; //Convert number a to stream ...
Posted by neverett on Sat, 05 Mar 2022 06:14:38 +0100