- 博客(56)
- 收藏
- 关注
原创 gdb 调试与strip
上面说了那么多废话,无非就是想mark如下几点实际嵌入式板子上跑的多时strip过后的,且多没有符号表,当产生core文件时,需要使用未strip符号表的版本来gdb调试编译优化之后,gdb调试core会丢失很多信息。
2023-04-26 23:48:13 896
原创 std::transform,std::back_inserter的小配合
下面是fast-rtps里的一段代码 do { // copy ordinary locators till the first ANY old_it = it; it = std::find_if(it, UnicastLocatorList.end(), IPLocator::isAny); // copy ordinary locators std::copy(old_it, it, std::back_
2022-03-18 17:19:56 781
原创 c++之std::future与shared_future是如何解决get多次的问题
这里只是想分析一下c++标准库是如何实现future以及shared_future的多次get问题。至于future的实现原理,基本可以归纳为自旋锁加内存序。这里就不展开,可以参考这篇文章。std::future如何实现1. 问题来了首先,很多书里介绍的是std::future不能多次get,而为了解决这个问题,引入了std::shared_future。下面我们看下例子#include <iostream>#include <future>#include <st
2022-02-17 15:02:45 2582
原创 c++之vector以及deque的一些思考,以及pop与push的具体实现
今天在分析threadsafe_stack代码时发现自己对pop和push的具体实现原理以及注意事项还是有点疏漏,然后撸了一遍相关标准库代码,记录一下。先说结论:pop与erase只是移动指针,不会删除内存,但是会调用该位置的析构函数,所以直接用变量引用这块内存是可以的,且不会出错emplace与push如果都是传入右值,那么实际使用上的区别就是emplace的不会调用析构函数,push进去的会调用析构函数move拷贝完了,原来的对象是会析构的pop与erase下图为vector< T
2022-02-14 16:26:21 1625
原创 c++之std::unique_lock, std::lock, std::scoped_lock及std::condition_variable
cpp_reference_std::scoped_lockcpp_reference_std::unique_lockscope_lock与lock_guard区别std::lock_guard or std::scoped_lockC++多线程unique_lock详解
2022-01-29 21:00:53 3556
原创 c++17之std::optional,std::variant以及std::any
std::optional#include <iostream>#include <optional>#include <string>#include <functional>#include <vector>using namespace std;class T{ public: T(int i):a(i){cout<<"the value is "<<i<<endl;}
2022-01-28 14:07:50 1913
原创 c++之std::declval 和 decltype以及std::result_of,invoke_result
https://juejin.cn/post/7021306822350864414std::declval 和 decltypehttps://www.jianshu.com/p/6606796de366c++11: std::declval/std::decltype#include<utility>#include<iostream>int test(int a,int b){ int c = a+b; std::cout<<"Run Te
2022-01-18 14:27:38 1722
原创 getopt_long解析parser
getopt_long函数分析1. man getopt_long #include <unistd.h> int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; #include <geto
2021-12-19 16:44:40 505
原创 linux开机自启动脚本以及update-rc.d命令解析
linux有很多种自启动方式,这里只是简单记录下update-rc.d的自启动方式update-rc.d的介绍update-rc.d命令用于安装或移除System-V风格的初始化脚本连接。脚本是存放在 /etc/init.d/目录下的,我们可以直接在/etc/init.d/目录下创建执行脚本,然后在rcN.d或者rcS.d中创建软链接,系统启动时会从rcS-rc0…rc6顺序启动文件夹里的启动脚本在/etc/目录下存在如下八个文件夹,7个rcN和一个rcSliuge@liuge-VirtualBox
2021-11-30 14:24:36 5666 3
原创 C++中关于using的两种用法
using两种特殊用法最近看ap代码,遇到了关于using的写法,代码如下,查了半天没找到ClientSocket(handle)是个什么东西。。。class StreamSocket : public ClientSocket {explicit StreamSocket(int handle) : ClientSocket(handle) {}}class ClientSocket : public Socket { public: using Socket::Socket; pro
2021-09-27 15:04:47 1161
原创 muduo源码分析3——TSD
#include <iostream>using namespace std;pthread_t tid1,tid2;pthread_key_t key;void deleter(void*){ cout<<"deleter"<<endl;}void* thread_fun2(void*){ int myValue = 2; int priValue = 11; pthread_setspecific(key,(void
2020-12-06 11:11:00 1066 10
原创 muduo源码分析1——CountDownLatch的使用(以及ptr_vector与vector<shared_ptr>性能分析)
1. CountDownLatch是什么分析muduo::Thread时,看到Thread::start函数,如下所示,其作用为启动线程(关于muduo thread相关的内容,下次写个博客详细分析) CountDownLatch latch_;void Thread::start(){ assert(!started_); started_ = true; // FIXME: move(func_) detail::ThreadData* data = new detail::
2020-11-28 16:06:20 346
原创 C++ 模板特化与偏特化
//// main.cpp// ticketmachine//// Created by Python_liu on 2019/8/6.// Copyright © 2019 liuxz. All rights reserved.//#include "TicketMachine.hpp"#include <iostream>#include <lis...
2020-11-20 23:25:25 619
原创 C++——并发基础tid、pid
对于linux来讲,线程即是进程通过pthread_self获取的为线程ID,为posix进程内部区分线程的idgetpid获取的是当前进程的pid通过系统调用syscall(SYS_gettid)获取的是tid,对于内核来讲就是该进程的pid对于只有一个线程的进程来说,pid就是tid对于有多个线程的进程来说,tid不等于pid,也不等于pthread_self获取的线程id#include <iostream>//#define _GNU_SOURCE /*
2020-11-20 16:02:44 1249
原创 C++——并发之std::async使用注意的坑,以及promise,future
async以及获取时间#include <future>#include <iostream>#include <time.h>int fun(int i){ std::cout<<"go!"<<std::endl; std::this_thread::sleep_for(std::chrono::seconds(5)); std::cout<<"hello"<<i<<
2020-11-19 17:43:15 10751 2
原创 C++中类成员函数被当作thread入参时注意点
1. pthread_create与std::threadpthread_create:void *(*start_routine) (void *) 注意入参的类型 #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), vo
2020-11-09 23:24:57 2890 5
原创 STL——remove_if
remove_ifremove_if(beg, end, op) //移除区间[beg,end)中每一个“令判断式:op(elem)获得true”的元素;remove_if函数返回result迭代器,其指向的最后一个元素remove_if需要配合对象的erase函数使用,才能删除满足条件的元素,否则,只改变原对象的内存排布,将符合条件的元素向前移动源码观察其源码,使用(__result)和 (__first)指向同一块内存,使用(__first)指向首地址,例如指向"Text with
2020-10-27 23:22:33 607
原创 lambda和shared_ptr的内存泄漏
shared_ptrhttps://floating.io/2017/07/lambda-shared_ptr-memory-leak/#include <iostream>#include <functional>#include <memory>//#include <boost/enable_shared_from_this.hpp>class my_class :public std::enable_shared_from_this<
2020-10-23 00:22:39 4414
原创 UNP——TCP回射服务器
server#include <stdio.h>#include <stdlib.h>#include "tcpser.h"#include <arpa/inet.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/time.h>#include <sys/select.h>#inclu
2020-07-01 17:57:06 275
原创 UNP——TCP分析
tcpserver.c#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <unistd.h>#include <sys/socket.h>#include <sys/types.h>#include <time.h>#include <arpa/inet.h>#include "proto.h"#define ba
2020-06-15 22:47:14 956
原创 APUE——信号基础以及信号的响应
1.信号基础1.1 信号函数#include <signal.h>void (*signal(int signo, void (*func)(int)))(int); 这是可靠写法void (* signal( int signo, void (*func)(int) ) )(int);函数名 :signal函数参数 :int signo, void (*func)(int)返回值类型:void (*)(int);信号的忽略: 信号忽略的核心是将mas
2020-05-21 16:28:22 365 1
原创 lambda以及易错点分析
[]是与外界交换的参数,()是lambda作为仿函数实际需要使用的参数,mutable是指如果[]里的参数是值传递,则只读,rettype是返回值类型
2020-05-21 10:23:04 955 1
原创 C++左值与右值以及std::move详解
1、左值与右值左值可以取地址,右值不可取地址左值具名,对应指定内存域,可访问;右值不具名,不对应内存域,不可访问。临时对像是右值。左值可处于等号左边,右值只能放在等号右边。区分表达式的左右值属性有一个简便方法:若可对表达式用 & 符取址,则为左值,否则为右值。左值可以在等号右边,可以在左边,但是右值必须在等号右边int a; a = 1; // here, a is an ...
2020-05-21 10:21:15 904
原创 Effective C++——构造析构等
template<typename T>class NameObject{ public: NameObject(const char* name, const T& value):nameValue(name),objectValue(value){}; NameObject(const string& name, const T&...
2020-05-21 10:19:56 133
原创 Effective C++——内存管理之make_shared
条款17 以独立语句将NEW置入智能指针如果有一个函数int priority()void processWidget(shared_ptr< Widget> pw, int priority),由于shared_ptr的构造函数template< class T> template< class U> explict shared_ptr(*U t)是需...
2020-05-21 10:19:33 260
原创 Effective c++笔记----const
1. 用const对象或者enums替换#defines1.const与define原来写法现在写法原因const char* const authorName=“ScottMeyers”const std::string authorName(“Scott Meyers”)#define ASPECT_RATIO 1.653const double Aspe...
2020-05-21 10:19:21 235
原创 const_cast、static_cast、dynamic_cast、reinterpreter_cast分析
C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用。参考链接四种类型分析注意使用这几种类型转换,得到的是对象,而不是类型const_cast,字面上理解就是去const属性。static_cast,命名上理解是静态类型转换。如int转换成char。参考链接static_cast详解dynamic_cast,命名上理解是动态类型转换。如子类和父类之间的多态类型转换。...
2020-05-21 10:18:40 213
原创 C++ bind与回调函数
回调函数函数1,2 为一个模块,为回调函数,函数3为一个模块,为注册回调函数,形参为函数指针注册回调函数的入参为函数指针,指向回调函数,回调函数实际就是指针类型的实例化与类无关的回调函数void basketball()//函数1{ printf("选择篮球");}void football()//函数2{ printf("选择足球");}void sele...
2020-05-21 10:18:22 3522
原创 STL——vector以及emplace_back分析
1、这里需要注意凡是连续空间的容器都提供operator[],[]是为了数组操作2、back()应该是*(end()-1)!!!3、vector的大小为12;vector的迭代器为指针
2020-05-21 10:16:42 10887 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人