111111

mmap主要用来做内存映射的,可以将虚拟内存和磁盘上的文件直接映射。共享映射中有一种机制叫做sync同步机制,对一端的修改会实时同步到另一端,这也是通过文件共享映射实现进程通信的基础。

9.1 什么是零拷贝? | 小林coding (xiaolincoding.com)

 

c++之指针和引用作为函数参数传递时的区别_指针和引用作为函数参数区别-CSDN博客

四种类型转换

static_cast

是一种静态的转换,在编译期就能确定的转换

dynamic_cast

不太安全(非法访问)

常量指针被转化成非常量的指针,并且仍然指向原来对象

[C++11] 理解右值引用及相关概念(左值与右值、std::move、完美转发)_std::move和完美转发-CSDN博客

牛逼:

#include <iostream>
#include <utility> // For std::forward
 
// 模拟一个可以接收左值引用和右值引用的函数
void process(int& x) {
    std::cout << "process(int&) - Lvalue reference" << std::endl;
}
 
void process(int&& x) {
    std::cout << "process(int&&) - Rvalue reference" << std::endl;
}
 
// 模板函数,使用完美转发将参数转发给process函数
template<typename T>
void wrapper(T&& arg) {
    // 使用std::forward来转发参数,保持其原始的类型和值类别
    process(std::forward<T>(arg));
}
 
int main() {
    int a = 10;
    wrapper(a);  // 编译器将调用 process(int&),因为a是左值
    wrapper(10); // 编译器将调用 process(int&&),因为10是临时对象(右值)
}

失败案例:

template<typename T>
void forward_to_function(T param) {
    // 没有使用 std::forward,直接传递参数
    some_other_function(param);
}

void some_other_function(int& lval) {
    // 接受左值引用
    std::cout << "Lvalue reference to int" << std::endl;
}

void some_other_function(int&& rval) {
    // 接受右值引用
    std::cout << "Rvalue reference to int" << std::endl;
}

int main() {
    int x = 10;
    
    // 传递左值
    forward_to_function(x);  // 预期输出: Lvalue reference to int
    // 传递右值
    forward_to_function(20); // 预期输出: Rvalue reference to int
    
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值