欢迎回到现代C++

本文介绍了现代C++强调的基于栈的内存管理,对比了堆和静态全局内存管理的优缺点。栈内存管理通过智能指针如`std::shared_ptr`实现自动引用计数,确保安全释放。文章还探讨了Copy和Move构造函数、LReference和RReference的概念,以及如何避免类设计中的内存管理错误。建议使用C++标准库容器和算法以提高代码安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

现在C++的岗位几乎都要求会使用C++11以后的标准,正好微软官方有一章就是讲的“Welcome Back to C++ (Modern C++)”,我这里主要在内存方面介绍下。具体请看看官方文档:https://docs.microsoft.com/en-us/cpp/cpp/welcome-back-to-cpp-modern-cpp?view=vs-2019

先来个总纲:

Modern C++ emphasizes:

  • Stack-based scope instead of heap or static global scope.

  • Auto type inference instead of explicit type names.

  • Smart pointers instead of raw pointers.

  • std::string and std::wstring types (see <string>) instead of raw char[] arrays.

  • C++ Standard Library containers like vectorlist, and map instead of raw arrays or custom containers. See <vector><list>, and <map>.

  • C++ Standard Library algorithms instead of manually coded ones.

  • Exceptions, to report and handle error conditions.

  • Lock-free inter-thread communication using C++ Standard Library std::atomic<> (see <atomic>) instead of other inter-thread communication mechanisms.

  • Inline 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值