C++11中enable_shared_from_this的用法解析
https://blog.csdn.net/breadheart/article/details/112451022

cpp feature

https://godbolt.org/
stacktrace -> gcc 12
source_location -> gcc 11/clang 15/msvc 19.29
ranges views -> gcc 10/clang 16/msvc 19.32
coroutine -> gcc 11/clang 13(not apple clang)/msvc 19.30
deducing this -> msvc 19.32/
format/print -> clang 17/msvc 19.37(/std:c++latest)

C++ 实现lambda递归调用(C++11 - C++23)

https://blog.csdn.net/J__M__C/article/details/125437699
https://wandbox.org/

https://zh.cppreference.com/w/cpp/feature_test

cppref note

无后缀浮点常量拥有 double 类型。若 后缀 为字母 f 或 F ,则浮点常量拥有 float 类型。若 后缀 为 l 或 L ,则浮点常量拥有 long double 类型。

C++11新特性3 - 左右值与右值引用
https://zhuanlan.zhihu.com/p/85668787

有限定的名字查找
如果 :: 左边为空,那么查找过程只会考虑全局命名空间作用域中作出(或通过 using 声明引入到全局命名空间中)的声明。这使得即使被局部声明隐藏的名字也能够被访问:

C++中的mutable关键字
https://www.cnblogs.com/yongdaimi/p/9565996.html
显而易见,mutable只能用来修饰类的数据成员;而被mutable修饰的数据成员,可以在const成员函数中修改。

friend有点类似

从函数返回时,作为求值函数调用结果的临时量的复制初始化按顺序早于在 return 语句的操作数末尾处对所有临时量的销毁,而这些销毁进一步按顺序早于对环绕 return 语句的块的所有局部变量的销毁。

构造函数不能是虚函数(因为在调用构造函数时,虚表指针并没有在对象的内存空间中,必须要构造函数调用完成后才会形成虚表指针)

虚析构函数是为了解决基类的指针指向派生类对象,并用基类的指针删除派生类对象。

别让异常逃离析构函数(析构函数应该吞下不传播异常,或者结束程序,而不是吐出异常;如果要处理异常应该在非析构的普通函数处理)

counting_semaphore

不同于 std::mutex , counting_semaphore 不捆绑到执行线程——能在不同于释放信号量的线程获取该信号量。能同时进行 counting_semaphore 上的所有操作而无需联系到任何特定的执行线程,除了不能同时执行,但能在一个不同的线程上执行析构函数。

信号量亦常用于发信/提醒而非互斥,通过初始化该信号量为0 从而阻塞尝试 acquire() 的接收者,直至提醒者通过调用 release(n) “发信”。在此方面可把信号量当作 std::condition_variable 的替用品,通常它有更好的性能。

Mutex只能由获取它的线程释放,而您可以从任何其他线程(或进程)发出信号量信号,因此信号量更适合某些同步问题,如producer-consumer。

在Windows上,二进制信号量更像是事件对象而不是互斥体。
https://www.codenong.com/62814/

std::list和std::forward_list

https://zh.cppreference.com/w/cpp/container/list
std::list 是支持常数时间从容器任何位置插入和移除元素的容器。不支持快速随机访问。它通常实现为双向链表。与 std::forward_list 相比,此容器提供双向迭代但在空间上效率稍低。
https://zh.cppreference.com/w/cpp/container/forward_list
std::forward_list 是支持从容器中的任何位置快速插入和移除元素的容器。不支持快速随机访问。它实现为单链表,且实质上与其在 C 中实现相比无任何开销。与 std::list 相比,此容器在不需要双向迭代时提供更有效地利用空间的存储。

std::recursive_mutex

有时候会在两个函数中分别对数据进行lock,如果在一个函数中又调用了另一个函数,此时如果使用std::mutex将会死锁,而用std::recursive_mutex则不会。看起来std::recursive_mutex很不错,但是使用的时候也需要多注意,lock和unlock的数量必须相等,否则会出错。

另外还有性能的问题,std::recursive_mutex的性能会比较差一些

std::unique_lock与std::lock_guard

https://www.jianshu.com/p/7eba4f722e07
std::condition_variable 对象通常使用 std::unique_lock 来等待,如果需要使用另外的 lockable 类型,可以使用std::condition_variable_any类

condition_variable(条件变量),通俗的将线程根据条件去拿锁,若不符合条件则休眠,直到有线程唤醒它才会继续去竞争锁,用于线程同步,只能配合unique_lock使用,前面3个wait函数需要传入一个已经上锁的变量unique_lock,此外第二个参数传入lambda表达式用于防止虚假唤醒;而condition_variable_any可以应用于任意的lock;

C++锁的管理– std::lock_guard和std::unique_lock
https://blog.51cto.com/u_15127564/3587504?b=totalstatistic

https://zh.cppreference.com/w/cpp/thread/lock
用免死锁算法避免死锁。
std::scoped_lock 提供此函数的 RAII 包装,通常它比裸调用 std::lock 更好。

std::weak_ptr 是一种智能指针,它对被 std::shared_ptr 管理的对象存在非拥有性(「弱」)引用。在访问所引用的对象前必须先转换为 std::shared_ptr。

std::weak_ptr 用来表达临时所有权的概念:当某个对象只有存在时才需要被访问,而且随时可能被他人删除时,可以使用 std::weak_ptr 来跟踪该对象。需要获得临时所有权时,则将其转换为 std::shared_ptr,此时如果原来的 std::shared_ptr 被销毁,则该对象的生命期将被延长至这个临时的 std::shared_ptr 同样被销毁为止。

std::weak_ptr 的另一用法是打断 std::shared_ptr 所管理的对象组成的环状引用。若这种环被孤立(例如无指向环中的外部共享指针),则 shared_ptr 引用计数无法抵达零,而内存被泄露。能令环中的指针之一为弱指针以避免此情况。

misc

https://winbgim.codecutter.org/
https://libxbgi.sourceforge.net/
https://lcc-win32.services.net/

avilib -> Rainer Johanni
player -> MCI mciSendCommand
https://learn.microsoft.com/zh-cn/windows/win32/multimedia/mci

https://github.com/leixiaohua1020/simplest_media_play

各系统添加根证书
https://www.cnblogs.com/meilong/p/ge-xi-tong-tian-jia-gen-zheng-shu.html

format str -> python -> c++ fmtlib

C++ 项目编译优化:记一次提速 60% 的实践
https://zhuanlan.zhihu.com/p/466738535
json_fwd.hpp

windows -> robocopy/forfiles/runas

cimg -> x11/win32 -> not apple

基于范围的 for 循环—自定义类型
https://zhuanlan.zhihu.com/p/354609822
https://learnmoderncpp.com/2019/11/18/pythons-range-in-20-lines-of-c/

C++20之模板元条件判断,编译期if else, switch case

std::decay 主要是弱化一些类型,说白了就是通过typedef 的方式去除掉引用、cv等属性。一般std::decay 与std::is_same 配合使用,确认基础类型。

探索X86架构C可变参数函数实现原理 -> va_list/__cdecl

https://blog.csdn.net/m0_50662680/article/details/127709109
AArch64中va_list/va_start/va_arg/…的实现
https://blog.csdn.net/lidan113lidan/article/details/123962416

c++自定义迭代器练习
https://blog.csdn.net/wyg_031113/article/details/128277587

struct 内成员初始化
成员是class的情况 c++会调用构造函数 此时gcc
默认初始化为0的情况(基础类型?)
mingw gcc/mingw clang/apple clang(-O1)部分
Uninitialized variable warnings and compiler optimizations
http://jakegoulding.com/blog/2011/01/27/uninitialized-variable-warnings-and-compiler-optimizations/

1
2
3
4
5
6
7
8
struct A{};
struct A = {}; // -pedantic warn
// gcc -> warning: ISO C forbids empty initializer braces before C2X [-Wpedantic]
// clang -> warning: use of GNU empty initializer extension [-Wgnu-empty-initializer]
struct A = {0}; // ok for c
// but c++ not happy
// gcc -> warning: missing initializer for member 'b' [-Wmissing-field-initializers]
// clang -> warning: missing field 'b' initializer [-Wmissing-field-initializers]

C++11编译问题:

1
// warning: ISO C++11 does not allow conversion from string literal to 'char *'

https://blog.csdn.net/qq_35683407/article/details/119603415

gcc -Wuninitialized会warn
clang编译好像没有警告 clang –analyze可以
msvc /permissive检查比较严格

https://curl.se/docs/caextract.html

gcc与vs2013的三个charset编译选项
https://www.cnblogs.com/findumars/p/6627255.html
https://zh.cppreference.com/w/c/language/translation_phases

C 语言中 static 的作用
https://www.runoob.com/w3cnote/c-static-effect.html

1
char *🐱 = "cat"; // 实现定义( Clang 可用,但版本 10 前的 GCC 不可)

确定对象身份(左值求值)或读取之前赋给对象的值(右值求值)
https://zh.cppreference.com/w/c/language/eval_order

c构造函数
https://www.cnblogs.com/imlgc/archive/2014/06/25/3808507.html
https://www.orcode.com/question/217772_k204b7.html

在main函数启动前和退出后执行代码
https://www.cnblogs.com/shokey520/p/3680804.html

gcc由于全局对象的构建和析构都是由运行库完成的,于是在程序或共享库中有全局对象时,记得不能使用“-nonstartfiles”或“-nostdlib”选项,否则,构建与析构函数将不能正常执行(除非你很清楚自己的行为,并且手工构造和析构全局对象)。

select、poll、epoll程序实例
https://www.cnblogs.com/bugutian/p/4816764.html

https://code.saghul.net/2016/05/libuv-internals-the-osx-select2-trick/

ps使用
ps -wwo args -p7230
ps -wwo comm -p7230
ps -cwwo comm -p7230
ps -chwwo comm -p7230
ps -wwo comm,args -p7230

wrk测试
wrk -c12 -d3s -t1 http://www.meitulu.cn/ -H “Accept-Encoding: deflate, gzip”
bombardier -c12 -d3s http://www.meitulu.cn/ -H “Accept-Encoding: deflate, gzip”

breakpad生成dmp

1
2
3
4
lldb -c 8F1E87E4-11F2-4646-BDC5-ABDAEC89FC69.dmp

free((int*)0xFEE1DEAD);
delete reinterpret_cast<int*>(0xFEE1DEAD);

Rust
http://mirrors.ustc.edu.cn/help/crates.io-index.html
https://rsproxy.cn/

https://lief-project.github.io/
LIEF : Library to Instrument Executable Formats
This project aims at providing a cross platform library to parse, modify and abstract ELF, PE and MachO formats.

Windows On Arm Resources
https://linaro.atlassian.net/wiki/spaces/WOAR/overview

https://www.likecs.com/ask-1171204.html
https://snai.pe/posts/c-smart-pointers
https://blog.csdn.net/guyueshanliangxin/article/details/106474989

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define auto_free __attribute__ ((cleanup(sfree)))

__attribute__((always_inline))
inline void sfree(void* str)
{
if( !str ) return;
free( *(void**)str );
printf("auto release\n");
}

void func()
{
auto_free char* tmp_str = calloc(100,1);
}

蚂蚁加速器 windows端口转发给macos或其他局域网设备使用

netsh interface portproxy add v4tov4 listenport=1081 listenaddress=10.106.19.66 connectport=1080 connectaddress=localhost
netsh interface portproxy show all
netsh interface portproxy delete v4tov4 listenport=1081 listenaddress=10.106.19.66
netsh advfirewall firewall add rule name=ANT_PROXY dir=in action=allow protocol=tcp localport=1081
netsh advfirewall firewall delete rule name=ANT_PROXY
注意事项: 可能需要先关掉防火墙 ping权限(文件和打印机共享)
#netsh advfirewall firewall show rule dir=in type=dynamic status=enabled name=ANT_PROXY
#netsh advfirewall firewall show rule name=all dir=in type=dynamic status=enabled
Ref: https://blog.csdn.net/vr7jj/article/details/80531353
https://www.cnblogs.com/boltkiller/articles/5732497.html

2021-06-01-WSL 2 兼容性问题
dism.exe /Online /Disable-Feature /FeatureName:Microsoft-Hyper-V-All
https://www.jianshu.com/p/5f3cb933f9b6
Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

linuxaudit –> libaudit –> audit_open()

brew install llvm
export PATH=”/opt/homebrew/opt/llvm/bin:$PATH”

// 0x00000001 | // File read (fr)
// 0x00000040 | // File close (cl)
// 0x20000000 | // ioctl (io)
非常频繁

ArchLinux systemd

docker commit -m “manjaro” 7f359fcf09b0 manjaro
docker run -it -d –entrypoint=/usr/lib/systemd/systemd –mount type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup –mount type=tmpfs,destination=/run manjaro bash

pacman color

sudo sed -i “s/#Color/Color/g” /etc/pacman.conf

clang -pg支持 Richard Smith, 6年前 (1 25th, 2017 3:39 凌晨)

https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-pg

名称查找进程

man pgrep
pgrep, pkill – find or signal processes by name
taskkill ?for windows

vm

Android –> termux/aidlearning
iOS –> iSH Shell/UTM

1
2
3
4
5
6
7
8
9
10
11
https://blog.csdn.net/qq_43652666/article/details/125161234

vmware此平台不支持虚拟化的 Intel VT-x/EP

https://blog.csdn.net/u013511036/article/details/126049334

此平台不支持虚拟化的Intel VT-x/EPT

WSL2依赖虚拟机平台 与Intel VT-x/EPT冲突

macOS无法启用IOMMU

Package.swift

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import PackageDescription
let package = Package(
name: "hello",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.6.1")),
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "4.0.0"),
],
targets: [
.executableTarget(
name: "hello",
dependencies: ["SwiftyJSON", "Alamofire"]),
.testTarget(
name: "helloTests",
dependencies: ["hello"]),
]
)

maven spring

/Users/wurui/.m2/wrapper/dists/apache-maven-3.8.6-bin/1ks0nkde5v1pk9vtc31i9d0lcd/apache-maven-3.8.6/conf/settings.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>public</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
<mirror>
<id>spring</id>
<mirrorOf>central</mirrorOf>
<name>spring</name>
<url>https://maven.aliyun.com/repository/spring</url>
</mirror>

glfw cmake

1
2
3
4
5
find_package(glfw3 REQUIRED)
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

qtbase macOS ninja build

1
2
3
4
cmake -Bbuild -GNinja
time ninja -C build
clang 13 3m40s -> 3m13s
clang 14 2m50s

理解全双工http
https://www.cnblogs.com/LoveOpenSourceBoy/p/14192243.html
http1.1:半双工
http2.0是全双工
HTTP/2推送服务器只能被浏览器来处理,而不是应用
HTTP2和WebSocket
https://www.cnblogs.com/yrxing/p/15799678.html
双工通信的Websocket
https://www.cnblogs.com/ltfxy/p/16320346.html
websocket实时通讯聊天室
https://www.cnblogs.com/ltfxy/p/12527794.html

1
2
3
4
5
6
xattr
ls -l@
xattr -l
xattr -d com.apple.quarantine
sudo xattr -r -d com.apple.quarantine
xattr -cr

XNU内核启动

osfmk/kern/startup.c
__startup_func
void
kernel_startup_bootstrap(void)
osfmk/kern/startup.h
#define __startup_func
 __PLACE_IN_SECTION(STARTUP_CODE_SEGSECT)
attribute((cold, visibility(“hidden”)))
osfmk/arm/arm_init.c
__startup_func
void
arm_init(
 boot_args *args)
osfmk/arm/start.s
LOAD_ADDR(lr, arm_init)

Windows 源码

WinNT4 https://github.com/ZoloZiak/WinNT4
https://github.com/Mooliecool/windows
WinNT5/XPSP1 https://github.com/jiubanlo/WinNT5_src_20201004

Shader book

https://thebookofshaders.com/?lan=ch

nim的特殊之处

函数括号省略 echo(“Hello”) –> echo “Hello”
第一个参数的形式化 sort(c) –> c.sort() –> c.sort

ruby 函数括号省略

lua的loadlib

返回的函数不支持参数
只能用于初始化

Lua完美打印一个Table的方案

https://www.cnblogs.com/leezj/p/4230271.html

xcode配置bitcode说明

https://www.jianshu.com/p/a971355877cb
对应iOS,bitcode是可选的。
对于watchOS,bitcode是必须的。
Mac OS不支持bitcode。

Xcode 弃用 Bitcode,导致应用体积大幅增加
https://www.oschina.net/news/217744/xcode14-increases-app-size

checksum

shasum - Print or Check SHA Checksums [shasum is implemented using the Perl module Digest::SHA.]

md5 data.png
openssl dgst -md5 data.png
openssl dgst -sha5 data.png

macOS文稿目录$HOME/Documents不适合开发 最新的系统会频繁提醒访问

https://www.brunerd.com/blog/2020/01/07/track-and-tackle-com-apple-macl/
xattr -l $HOME/Documents
ls -l -d $HOME/Documents
可用路径$HOME以及/Users/Shared

winget

https://winget.azureedge.net/cache

152.199.39.108 ping不通 新建账户也不行
虚拟机 Manjaro可以 系统设置故障??

消除Signal<void, string>指定类型 自动推导

参考src/corelib/kernel/qobjectdefs_impl.h

关于设计模式:SoA / AoS内存布局的C ++零成本抽象

https://www.codenong.com/50574639/

small_vector

https://github.com/p-ranav/small_vector/blob/master/include/small_vector/small_vector.h

1
2
3
4
template <class T, std::size_t N, class Allocator = std::allocator<T>> class small_vector {
std::array<T, N> stack_;
std::vector<T, Allocator> heap_;
std::size_t size_{0};

Enable sudo without a password on MacOS

https://jefftriplett.com/2022/enable-sudo-without-a-password-on-macos/

audit_event

cat /etc/security/audit_event | grep :pc

window system

  • linux (X Window)
    XOpenDisplay -> XCreateWindow -> XCreateImage -> XPutImage
  • macos
    NSWindow
  • windows
    CreateWindow

target <-> action

cell/control/menuitem
NSView->NSControl

关于堆栈

全局栈(全局区?) 无限制
若初始化字符串 生成的二进制膨胀 .global .text
栈大小 8192kbyte (m1 macmini) 包括alloca
线程限制 (代码栈+数据栈)
代码栈 递归和函数个数限制
数据栈 静态分配大小限制
栈几乎无分配开销
堆开销 malloc 40ns(m1 macmini)
1byte~10241024byte变化不大 10241024byte之后的某个点 开销上升60倍
10010241024byte 大概需要40us
结构体返回 栈拷贝

alloca使用例子 https://github.com/apache/apr/blob/trunk/poll/unix/poll.c#L80
栈上的链表 https://course.rs/too-many-lists/advanced-lists/stack-allocated.html

imagemagick

convert -size 32000x32000 pattern:checkerboard -auto-level +level-colors white,black tiff64:test.tif
convert -size 20000x20000 xc:skyblue skyblue.tif
convert -size 10000x10000 pattern:checkerboard checkerboard.tif
convert -size 5000x5000 pattern:checkerboard -auto-level +level-colors white,black checkerboard.tif

shuriken

https://github.com/per-gron/shuriken/blob/d826e295dc0bbf2c19c597035414f1ddec2e46fa/src/traceexec/README.md

macos log

1
2
3
log stream --predicate 'senderImagePath CONTAINS "tmp"'
log show --predicate 'senderImagePath CONTAINS "tmp"'
log help predicates
1
2
3
4
5
6
7
8
9
#ifdef KEXT
#include <libkern/libkern.h>
#define LOG(...) PrintCurrentProcess();printf("Echo: " __VA_ARGS__); printf("\n");
#define LOGE(...) PrintCurrentProcess;printf("Echo: [Error] " __VA_ARGS__); printf("\n");
#elif IOKIT_KEXT
#include <IOKit/IOLib.h>
#define LOG(...) PrintCurrentProcess;IOLog("IOKitEcho: " __VA_ARGS__); IOLog("\n");
#define LOGE(...) PrintCurrentProcess;IOLog("IOKitEcho: [Error] " __VA_ARGS__); IOLog("\n");
#endif

create_macos_recovery

https://github.com/rtrouton/create_macos_recovery
Note: macOS Big Sur (macOS 11.x) made significant changes to the Recovery volume and it is unlikely this script will support any version of macOS past macOS 10.15.x.

mach_msg_send/mach_msg_receive

https://github.com/apple-oss-distributions/xnu/blob/5c2921b07a2480ab43ec66f5b9e41cb872bc554f/libsyscall/mach/mach_msg.c#L314-L328

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mach_msg_return_t
mach_msg_send(mach_msg_header_t *msg)
{
return mach_msg(msg, MACH_SEND_MSG,
 msg->msgh_size, 0, MACH_PORT_NULL,
 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}

mach_msg_return_t
mach_msg_receive(mach_msg_header_t *msg)
{
return mach_msg(msg, MACH_RCV_MSG,
0, msg->msgh_size, msg->msgh_local_port,
 MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}

【摘录】OSX/iOS 的系统mach_msg浅解
https://www.jianshu.com/p/4596d2dd2d88
https://nshipster.com/inter-process-communication/
https://segmentfault.com/a/1190000002400329

pcap

https://github.com/GyulyVGC/sniffnet
https://github.com/rust-pcap/pcap/blob/main/src/raw.rs

man pcap
pcap -> bpf -> nke/ke

nmap+masscan 各自优缺点,快速上手综合使用

https://blog.csdn.net/qq_53079406/article/details/122922401
Masscan 最快的互联网IP端口扫描器
https://www.cnblogs.com/hubin123/p/16517022.html

Reactor和Proactor

Reactor 可以理解为「来了事件操作系统通知应用进程,让应用进程来处理」,而 Proactor 可以理解为「来了事件操作系统来处理,处理完再通知应用进程」。这里的「事件」就是有新连接、有数据可读、有数据可写的这些 I/O 事件这里的「处理」包含从驱动读取到内核以及从内核读取到用户空间。

如何深刻理解Reactor和Proactor?
https://www.zhihu.com/question/26943938

root函数指针

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ root -l
root [0] void func()
root [1] func
input_line_10:2:3: error: use of undeclared identifier 'func'
 (func)
  ^
root [2] void (*func)()
(void (*)()) Function @0x0
root [3] func
(void (*)()) Function @0x0
root [4] void func2(){}
root [5] func2
(void (*)()) Function @0x1196e8080
  at input_line_14:2:
void func2(){}

root [6] func = func2
(void (*)()) Function @0x1196e8080
root [7] func
(void (*)()) Function @0x1196e8080
root [8] func2
(void (*)()) Function @0x1196e8080
  at input_line_14:2:
void func2(){}

pcap -> bpf

man pcap_compile
man pcap-filter
sudo tcpdump port 53

plutil SystemExtensions

plutil -p /Library/SystemExtensions/db.plist

choco and scoop

choco安装需要 管理员 powershell
scoop需要powershell 不需要管理员
scoop需要退出登陆 PATH环境变量才生效

在 Windows 11 下安装和使用 SSH 连接远程服务器

https://www.yundongfang.com/Yun73222.html
Get-WindowsCapability -Online | Where-Object Name -like ‘OpenSSH*’
Add-WindowsCapability -Online -Name OpenSSH.Server
https://www.jianshu.com/p/9235e33c2ca0
sc query sshd
sc config sshd start=auto
sc start sshd

ssh免密登陆

ssh-copy-id -i .ssh/id_rsa.pub user@10.226.32.76
https://www.cnblogs.com/kasader/p/12760284.html