随笔分类 - 【01】C++
摘要:设计模式之PIMPL模式 参考资料 1. 设计模式之PIMPL模式
阅读全文
摘要:调试方法 用 c++filt 还原符号名: echo "_ZN5hf3fsfuseRC..." | c++filt 这样能看到它到底是 hf3fs::fuse::RC::something,还是一个全局对象。 然后你就能判断: 如果它是一个类方法 → 确认实现文件是否编进了 .so。 如果它是个全局
阅读全文
摘要:C++中只用指针而无需完整类型定义教程 在 C++ 里,如果你只用指针来引用一个类型,而不直接使用这个类型的成员或实例,是可以不需要完整定义该类型的,这叫做前向声明(forward declaration)。 1. 例子: #include <iostream> // 前向声明(不需要包含完整头文件
阅读全文
摘要:成员函数指针 在 C++ 中,类成员指针(pointer-to-member)是指向类的成员(可以是数据成员或成员函数)的指针。它和普通指针不一样,必须通过对象或者对象指针来访问。 数据成员指针声明方式: 类型 类名::*指针名; 示例 #include <iostream> struct MyCl
阅读全文
摘要:成员函数后加&的作用 参考资料 1. C++成员函数后加&的作用是什么?
阅读全文
摘要:requires关键字 requires 子句(clause):用于指定模板参数必须满足的约束条件: template<typename T> requires std::integral<T> T add(T a, T b) { return a + b; } 这也可以写成简化形式: templa
阅读全文
摘要:参考资料 1attribute__((packed))详解 2GCC的__attribute__扩展特性
阅读全文
摘要:函数__atomic_compare_exchange_n 1. 函数原型: bool __atomic_compare_exchange_n (type *ptr, type *expected, type desired, bool weak, int success_memorder, int
阅读全文
摘要:参考资料 1. 原子操作_atomic 系列函数
阅读全文
摘要:gcc内置原子操作 从GCC4.1.版本之后就引入了内置的原子操作函数,可对x86_64架构(除此之外还有其他类型)1、2、4、8字节的integer scalar或pointer使用,可有效减少对锁机制的使用进一步而提升效率,这些函数以__sync开头,而在GCC4.7之后的版本,这些函数被替换成
阅读全文
摘要:定位new表达式 当传入一个指针类型实参时,定位new表达式构造对象但是不分配内存。 new(address) type; new(address) type(initializers); new(address) type[size]; new(address) type[size]{braced
阅读全文
摘要:va_start和va_end使用详解 函数参数是以数据结构:栈的形式存取,从右至左入栈。首先是参数的内存存放格式:参数存放在内存的堆栈段中,在执行函数的时候,从最后一个开始入栈。因此栈底高地址,栈顶低地址,例如: void func(int x, float y, char z); 调用函数的时候
阅读全文
摘要:多重继承(无虚函数覆盖) 下面,再让我们来看看多重继承中的情况,假设有下面这样一个类的继承关系。注意:子类并没有覆盖父类的函数。 class Base1 { public: virtual void f() { cout << "Base1::f" << endl; } //虚函数定义 virtua
阅读全文
摘要:std::shared_ptr 下图显示了指向一个内存位置的几个 shared_ptr 实例: 看上面的例子,使用 std::shared_ptr 时,会涉及两次内存分配:一次分配共享资源对象;一次分配控制块。C++ 标准库提供了 std::make_shared 函数来创建一个 shared_pt
阅读全文
摘要:vscode安装插件 #include <algorithm> #include <iostream> #include <string_view> #include <tuple> #include <type_traits> namespace reflection { template <cl
阅读全文
摘要:clang安装 安装依赖包: sudo dnf groupinstall "Development Tools" sudo dnf install cmake ninja-build python3 gcc-c++ 下载clang进行编译安装: # 克隆 LLVM 项目 git clone http
阅读全文
摘要:ceph关于make编译打包制作 find ceph-18.2.2/ -name .gitignore | sed -e "p;s/.gitignore/.gitignore.sunbin/" | xargs -n2 mv git add . git commit --amend find ceph
阅读全文
摘要:协程coroutine #include <coroutine> #include <iostream> using namespace std; struct CoRet { struct promise_type { suspend_never initial_suspend() { retur
阅读全文