c++
Harvey_jiang
这个作者很懒,什么都没留下…
展开
-
c++11 线程管理
线程回收启动线程后,在线程销毁钱需要对其调用join或deteach否则会调用std::terminatejoin()使用join可以保证局部变量在线程结束后才被销毁不可以重复join启动线程后的操作可能发生异常可以通过捕获异常,并在处理异常时调用join#include <iostream>#include <thread>#include <chrono>int main(){ int num = 5; std::thread原创 2020-12-10 14:23:33 · 171 阅读 · 0 评论 -
智能指针传参
一个奇奇怪怪的测试shared_ptr进行引用传递引用计数不变,内存正常释放#include <iostream>#include <memory>using namespace std;class Base{public: Base(int num = 0):num(num) { cout << "Base::Base()" << endl; } ~Base() { cout << "Base::~Base()原创 2020-12-08 16:35:49 · 1908 阅读 · 0 评论 -
vs下检测程序是否有内存泄露
添加头文件和宏定义#include <crtdbg.h>#ifdef _DEBUG#define new new (_NORMAL_BLOCK, __FILE__, __LINE__)#endif在main函数最后添加_CrtDumpMemoryLeaks();没有内存泄露的测试代码和调试信息#include <crtdbg.h>#include <iostream>#ifdef _DEBUG#define new new (_NORMAL_原创 2020-12-08 15:49:53 · 207 阅读 · 0 评论 -
ace-1
ACE_SOCK_Stream 建立通信流 ACE_SOCK_Acceptor 建立被动连接 ACE_SOCK_Connector 建立主动连接 ACE_INET_Addr 实现对IP的封装操作使用ace实现通信的过程服务器ACE_INET_Addr(port) 传入监听端口等 ACE_SOCK_Acceptor acceptor acceptor.open原创 2017-06-20 00:31:45 · 221 阅读 · 0 评论 -
c++11线程基本用法
qt支持c++11,添加 QMAKE_CXXFLAGS += -std=c++0x CONFIG += C++111.放入函数#include <iostream>#include <string>#include <thread>#include <memory>void threadFunc(int num){ ...原创 2018-06-15 23:50:15 · 511 阅读 · 0 评论 -
c++调用脚本计算sha512
计算摘要命令 sha512sum checkSha.sh#!/bin/bashif [ &quot;$1&quot; = &quot;sha512&quot; ]then sha512sum $2| awk '{print $1}' exit 0fiif [ &quot;$1&quot; = &quot;md5&quot; ]then原创 2018-06-27 01:00:13 · 359 阅读 · 0 评论 -
【转】C++协程库coroutine使用
转自https://blog.csdn.net/hellufo2/article/details/53609487 https://my.oschina.net/attobit/blog/753962 项目源码 https://github.com/tonbit/coroutine创建协程:routine_t create( std::function#include &lt;iost...转载 2018-09-06 01:03:46 · 1123 阅读 · 0 评论 -
QFile按行读取分割xml文件
xml文件很大时不方便操作按行读取切割xml文件枚举值 描述QIODevice::NotOpen 未打开QIODevice::ReadOnly 以只读方式打开QIODevice::WriteOnly 以只写方式打开QIODevice::ReadWrite 以读写方式打开QIODevice::Append 以追加的方式打开,新增加的内容将被追加到文件末尾QIODevice::Trun...原创 2019-04-29 00:59:14 · 456 阅读 · 0 评论