随笔分类 -  language:C/C++

摘要:在.vscode里创建三个文件 c_cpp_properties.json, launch.json, settings.json, tasks.json c_cpp_properties.json { "configurations": [ { "name": "GCC", "includePat 阅读全文
posted @ 2022-07-15 17:35 douzujun 阅读(352) 评论(0) 推荐(0) 编辑
摘要:rand() % (high - low + 1) + low; 阅读全文
posted @ 2022-07-08 12:45 douzujun 阅读(61) 评论(0) 推荐(0) 编辑
摘要:class Solution { void quickSort(vector<string>& strs, int l, int r) { if (l >= r) return; int i = l, j = r; while (i < j) { while(strs[j] + strs[l] >= 阅读全文
posted @ 2022-05-08 22:52 douzujun 阅读(192) 评论(0) 推荐(0) 编辑
摘要:1. 生成了一个线程,需要告诉编译器是否管理 必须告诉编译器是不管理还是管理,否则直接down了 1.1 可以通过join(),自己管理 如果遇到异常,没有调用join,自己可以写一个析构调用join() 1.2 通过detach(),不管理 detach适合不会出错,生命周期比整个程序短,不想管理 阅读全文
posted @ 2019-05-09 23:26 douzujun 阅读(775) 评论(0) 推荐(0) 编辑
摘要:1. 安装 2. 简单使用 3. 进阶 待续 阅读全文
posted @ 2019-05-07 20:26 douzujun 阅读(616) 评论(0) 推荐(0) 编辑
摘要:C的代码 打包成动态库之后 a改变了内容,没有改变指向,b改变了内容 更多: https://www.cnblogs.com/gaowengang/p/7919219.html 阅读全文
posted @ 2019-05-06 20:56 douzujun 阅读(1644) 评论(0) 推荐(0) 编辑
摘要:1. 遇到的问题 计算结果不一致!三个线程共享一份资源,有的加了有的没加。 2. 解决 2.1 法一:不共享变量 2.2 法二:原子操作变量类型(复杂,适合简单应用) b,c 线程共享了变量 counter2, 没有共享变量 totalValue,所以totalValue一样,counter2.co 阅读全文
posted @ 2019-05-05 21:09 douzujun 阅读(2991) 评论(0) 推荐(0) 编辑
摘要:1. 简介 2. 线程使用 2.1 demo 2.2 一个简单的应用 查看当前线程id: this_thread::get_id() 比较单线程和多线程工作的效率(如果工作不太消耗时间,多线程反而比单线程更耗时间) 阅读全文
posted @ 2019-05-04 23:52 douzujun 阅读(43333) 评论(4) 推荐(1) 编辑
摘要:1. 简单使用 阅读全文
posted @ 2019-05-03 15:41 douzujun 阅读(328) 评论(0) 推荐(0) 编辑
摘要:参考学习:https://www.cnblogs.com/xuelisheng/p/9339924.html 1. 回调函数定义 回调函数就是一个通过函数指针调用的函数。 如果你把 函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数。 回调函数不是 阅读全文
posted @ 2019-04-30 19:52 douzujun 阅读(1335) 评论(0) 推荐(0) 编辑
摘要:1. 几种智能指针 1. auto_ptr: c++11中推荐不使用他(放弃) 2. shared_ptr: 拥有共享对象所有权语义的智能指针 3. unique_ptr: 拥有独有对象所有权语义的智能指针 4. weaked_ptr: 到 std::shared_ptr 所管理对象的弱引用 1.1 阅读全文
posted @ 2019-04-29 23:55 douzujun 阅读(1114) 评论(0) 推荐(0) 编辑
摘要:参考: https://www.hahack.com/codes/cmake/ 1. 单目标文件 main.c CMakeLists.txt 然后 2. 同一个目录,多个源文件 calc_power.h calc_power.c main.cpp CMakeLists.txt 再执行 3. 多目录, 阅读全文
posted @ 2019-04-24 11:02 douzujun 阅读(717) 评论(0) 推荐(0) 编辑
摘要:转载: https://www.zhihu.com/question/23003213 1. C代码如何调用Python 1.1 test Linux下执行: 注意是Python2.7不是python3...不然好像报错.... 1.2 C调用Python函数 great_module.py inc 阅读全文
posted @ 2019-04-19 21:33 douzujun 阅读(641) 评论(0) 推荐(0) 编辑
摘要:1. alignas (c++11) 设置类和struct的字节对齐方式 默认取值是: 2n : 0, 1, 2, 4 , 6, 8..... 2. alignof 区分sizeof(), alignof得到字节对齐的字节数 3. auto (c++11) 4. bitand 和 bitor 5. 阅读全文
posted @ 2019-04-10 20:05 douzujun 阅读(1365) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2019-04-02 21:52 douzujun 阅读(250) 评论(0) 推荐(0) 编辑
摘要:1. 头文件 2. API函数 3. 最简单的服务器和对应的客户端C语言实现 3.1 server 3.2 client 当服务器主动关闭连接的时候,会出现 TIME_WAIT状态(哪一边主动关闭连接,TIME_WAIT发生在哪一边) 阅读全文
posted @ 2019-04-02 21:13 douzujun 阅读(1230) 评论(0) 推荐(0) 编辑
摘要:头文件:#include <string.h> memmove() 用来复制内存内容,其原型为: memmove() 与 memcpy() 类似都是用来复制 src 所指的内存内容前 num 个字节到 dest 所指的地址上。 不同的是,memmove() 更为灵活,当src 和 dest 所指的内 阅读全文
posted @ 2019-04-02 17:20 douzujun 阅读(1213) 评论(0) 推荐(0) 编辑
摘要:编译器中提供了#pragma pack(n)来设定变量以n字节对齐方式。n字节对齐就是说变量存放的起始地址的偏移量有两种情况:第一、如果n大于等于该变量所占用的字节数,那么偏移量必须满足默认的对齐方式,第二、如果n小于该变量的类型所占用的字节数,那么偏移量为n的倍数,不用满足默认的对齐方式。结构的总 阅读全文
posted @ 2019-04-02 15:20 douzujun 阅读(785) 评论(0) 推荐(0) 编辑
摘要:相差4字节 相差8个字节 原因: 这4个字节是优化掉了,64位操作系统,函数传参通过寄存器,减少了栈的使用 debug模式下,abc的地址都存下来了。 阅读全文
posted @ 2019-04-02 00:35 douzujun 阅读(280) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示