Browse Source

基础知识记录修改

kindring 1 year ago
parent
commit
d6dcdd418e
3 changed files with 82 additions and 3 deletions
  1. 28 3
      C与C++/c中基础函数用法.md
  2. 27 0
      C与C++/基本知识.md
  3. 27 0
      linux/开机自启相关.md

+ 28 - 3
C与C++/c中基础函数用法.md

@@ -51,9 +51,20 @@ int snprintf( char *buffer, size_t buf_size, const char *format, ... );//可变
 ## `memcpy` 函数
 ### 作用
 > En  
-> Copies count bytes from the object pointed to by src to the object pointed to by dest. Both objects are reinterpreted as arrays of unsigned char. If the objects overlap, the behavior is undefined. If either dest or src is a potentially-overlapping subobject (e.g., a field in a C-compatible struct) or is not TriviallyCopyable (e.g., scalar, C-compatible struct, or an array thereof), the behavior is undefined. If count is zero, the function does nothing.
-> Ch
-> 将src指向的对象的count个字节复制到dest指向的对象。两个对象都被重新解释为无符号字符数组。如果对象重叠,则行为是未定义的。如果dest或src是潜在重叠的子对象(例如,C兼容结构中的字段)或不是TriviallyCopyable(例如,标量,C兼容结构或其数组),则行为是未定义的。如果count为零,则函数不执行任何操作。
+> Copies count bytes from the object pointed to by src to the object pointed to by dest.  
+> Both objects are reinterpreted as arrays of unsigned char.  
+> If the objects overlap, the behavior is undefined.  
+> If either dest or src is a potentially-overlapping subobject   
+> (e.g., a field in a C-compatible struct) or is not TriviallyCopyable  
+> (e.g., scalar, C-compatible struct, or an array thereof),   
+> the behavior is undefined. If count is zero, the function does nothing.  
+> Ch  
+> 将src指向的对象的count个字节复制到dest指向的对象。  
+> 两个对象都被重新解释为无符号字符数组。  
+> 如果对象重叠,则行为是未定义的。  
+> 如果dest或src是潜在重叠的子对象(例如,C兼容结构中的字段)  
+> 或不是TriviallyCopyable(例如,标量,C兼容结构或其数组),  
+> 则行为是未定义的。如果count为零,则函数不执行任何操作。
 
 ### 语法
 ```c++
@@ -61,4 +72,18 @@ void *memcpy(void *dest, const void *src, size_t count);
 ```
 
 ### 参数
+- dest: 指向目标对象的指针
+- src: 指向源对象的指针
+- count: 要被复制的字节数
 
+### 实现
+```c++
+void *memcpy(void *dest, const void *src, size_t count)
+{
+    char *d = dest;
+    const char *s = src;
+    while (count--)
+        *d++ = *s++;
+    return dest;
+}
+```

+ 27 - 0
C与C++/基本知识.md

@@ -118,3 +118,30 @@ void fun(int *p)
     *p=20;
 }
 ```
+
+### & 与 * 的区别
+#### `#d` & 获取地址 | * 获取地址中的值
+&是取地址运算符,*是取值运算符
+#### `#e` & 获取地址 | * 获取地址中的值
+```c++
+int a;
+int *p=&a;
+printf("%d",*p); //输出a的值
+```
+## `#d` 指针的运算
+### `#e` 指针的运算
+```c++
+int a=10;
+int *p=&a;
+p=p+1;
+printf("%d",*p);//输出a的下一个地址的值
+```
+
+
+### sizeof
+#### `#d` 获取变量的大小
+```c++
+int a;
+int *p=&a;
+printf("%d",sizeof(p));//输出4
+```

+ 27 - 0
linux/开机自启相关.md

@@ -33,6 +33,33 @@ ExecStart= #server 执行的任务,此注释替换新的
 [Install]
 WantedBy=multi-user.target
 ```
+### ps 如果该服务需要使用到网络,则需要在`[Unit]`下添加
+```shell
+After=network.target network-online.target syslog.target
+Wants=network.target network-online.target
+```
+### ps 如果添加了网络配置还是提示无效,则可以使用自动重启功能
+```shell
+[Service]
+Restart=always
+RestartSec=3
+```
+#### 参数解释 
+1. 重启策略 Restart 
+- Restart=always 服务退出后总是重启
+- Restart=on-failure 服务退出后重启,除非退出代码为0
+- Restart=on-abnormal 服务退出后重启,除非退出代码为0,或者由于信号而退出
+- Restart=on-success 服务退出后重启,只有退出代码为0时才重启
+- Restart=on-abort 服务退出后重启,只有退出代码为0时才重启
+- Restart=never 服务退出后不重启  
+
+2. 重启间隔 RestartSec 
+- RestartSec=3 服务退出后3秒后重启
+- RestartSec=30s 服务退出后30秒后重启
+- RestartSec=1min 服务退出后1分钟后重启
+
+3. 重启次数 Limit
+- LimitRestart=3 服务退出后重启3次
 ### 启用服务
 ```shell
 sudo systemctl enable serverName