
c
Frozen2022
这个作者很懒,什么都没留下…
展开
-
__unaligned修饰指针
如果是未对齐的指针类型,编译器会报告警告(在itanium的VLIS架构下报错)。为了避免这种情况,使用__unainged修饰指针。如void__unaligned*p;通过插入额外的检查来检测非对齐情况,并分别加载/存储跨越对齐边界的对象部分。这甚至比原生支持它的平台上的非对齐访问还要慢。...原创 2022-07-31 07:57:52 · 750 阅读 · 0 评论 -
spin lock和mutex使用场景的差异
现代操作系统的做法,多核的环境中,在实现mutex时,如果lock操作后,进行短暂的轮询(spin lock),超过这段时间后,使用传统的mutex阻塞(加入挂起队列)。如果程序可预测的阻塞的时间较短,可以主动使用spin lock。在单核CPU下,spin lock没有意义,只会影响正常线程响应;使用mutex虽然会在“挂起”和“运行”两个队列间切换,但提高了系统整体的响应比。多核CPU下,spin lock在多个和核心上的轮询时间是可以忽略的,使用spin lock避免了因为队列切换导致的时间消耗。..原创 2022-07-29 09:18:02 · 376 阅读 · 0 评论 -
IRP结构的MdlAddress,UserBuffer,SystemBuffer三种内存的区别
支持的操作IRP_MJ_READ,IRP_MJ_WRITE,IRP_MJ_DEVICE_CONTROL,IRP_MJ_INTERNAL_DEVICE_CONTROL。用户空间的地址,进程切换后,失效。且这个内存对于驱动来说是只读的,也就是用户在I/O控制中指定的输出缓冲的内容。使用DirectI/O的驱动,支持的操作IRP_MJ_READ,IRP_MJ_WRITE,IRP_MJ_DEVICE_CONTROL,IRP_MJ_INTERNAL_DEVICE_CONTROL。.........原创 2022-07-18 09:45:23 · 760 阅读 · 0 评论 -
64位中断汇编不能使用
解决:包含头文件使用中断函数通过debug,我们看到了中断效果原创 2022-07-11 17:43:38 · 217 阅读 · 0 评论 -
可变参数重载时的内存错误
字符指针和可变参数列表重载原创 2022-07-03 15:18:00 · 175 阅读 · 0 评论 -
QtCreator的console工程无console弹框,无法接收键盘输入
解决:需要勾选Run in terminal。在Projects ——>Run——>Run in terminal截图:原创 2022-05-19 10:55:40 · 880 阅读 · 0 评论 -
C++全局变量初始化的顺序
虽然一直强调不要用全局变量。但是对于特殊的应用场合,还是有全局变量的使用(如某些多进程、多线程的共享资源),我们希望在首次运行(载入)时,系统能够帮助我们进行一些必要的初始化。对不同的源文件中的全局变量,标准C++对全局变量初始化的顺序并没有要求。对于同一个原文件中,全局变量按照定义先后顺序初始化。对于堆类型的全局变量的创建和构造,可能在一个构造函数中调用另一个未构造的全局变量,通常会检查另一个指针是否有效,并在无效时构造那个对象。这就出现一个问题:一个指针在构造之前,被初始化。c/c++运行时原创 2022-05-10 20:01:53 · 1914 阅读 · 0 评论 -
使用cef_sandbox.lib链接时报错:_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2”
解决方案:在预处理器的宏定义处加入:_HAS_ITERATOR_DEBUGGING=0关于的介绍请参考:微软MSDN在"安全库:C++ 标准库"中的相关介绍:_ITERATOR_DEBUG_LEVEL | Microsoft Docs详细了解:_ITERATOR_DEBUG_LEVELhttps://docs.microsoft.com/zh-cn/cpp/standard-library/iterator-debug-level?view=msvc-170...原创 2022-04-11 12:15:24 · 620 阅读 · 0 评论 -
lua的userdata的生存周期
userdata是一个特殊的table,它具有lua代码的所有表的特性。同时具有额外的:userdata。Userdata values cannot be created or modified in Lua, only through the CAPI. This guarantees the integrity of data owned by the host program.因为存在这片对C/C++绝对安全的内存,我们可以将C/C++对象与lua的table关联起来。如果能确定use.原创 2022-02-15 19:43:19 · 3335 阅读 · 0 评论 -
lua使用require加载成功共享库,但返回的是boolean(总是true)
先看require的帮助文档If the loader returns any non-nil value,requireassigns the returned value topackage.loaded[modname]. If the loader does not return a non-nil value and has not assigned any value topackage.loaded[modname], thenrequireassignstrueto t...原创 2022-02-12 08:28:07 · 1355 阅读 · 0 评论 -
使用libCurl进行百度图片翻译一直返回invalid_sign错误
官方文档写的请求方式为:请求方式:POST/GET原因:必须使用POST,因为图片参数必须通过curl_httppost添加。如果使用GET,会自动忽略curl_httppost。原创 2022-02-02 06:32:43 · 1195 阅读 · 0 评论 -
Qt中使用curl通过https下载数据崩溃
原因:http服务器发送到客户端的数据,如果使用gzip压缩,libcurl内部负责使用zlib解压缩。在编译libcurl时,如果使用的zlib和Qt内部的zlib版本不一致,会导致libcurl内部调用部分zlib接口时链接到Qt的zlib中,如:inflate_fast函数。解决:如果准备在Qt中使用libCurl,那么在编译libcurl时,指定zlib为Qt的zlib。...原创 2022-01-25 17:52:03 · 2271 阅读 · 0 评论 -
linux程序报错terminate called without an active exception
程序“正常”退出时产生此错误。1、主线程结束,子线程未结束;2、程序中有些函数返回类型不是void,但是没写return语句;3、其它。原创 2021-09-24 16:50:58 · 3439 阅读 · 0 评论 -
VS链接错误:Fatal Error C1060
compiler is out of heap spaceThe operating system or run-time library cannot fill a request for memory.To fix this error try the following possible solutions If the compiler also issues errorsC1076andC3859, use the/Zmcompiler option to lower th...转载 2021-08-31 22:53:20 · 882 阅读 · 0 评论 -
WIFI设备列表中存在多个重复设备
If a scaned network has matching profiles, there will be multiple entries in the list, one for each profile, and an additional entry for the network without profile. For example, if there are two profiles for SSIDMyWiFi, p1 and p2, you will see three entr.原创 2021-07-15 09:05:43 · 432 阅读 · 0 评论 -
Openssl调用SSL_Shutdown过快有时导致程序退出
这是由于tcp另一端断开连接后,通信管道会中断(Broken pipe),如果仍然尝试读写操作,此时在一些linux下,系统会发出SIGPIPE信号(默认处理时退出程序),由于openssl也会检测这个错误,因此,我们只需要在程序的main函数出加上忽略此信号:signal(SIGPIPE, SIG_IGN);...原创 2021-06-23 13:27:26 · 1166 阅读 · 1 评论 -
源代码恢复:使用IDA Pro反汇编obj文件
有时候系统或环境出错导致代码丢失或恶意篡改,如果这发生在提交源代码管理之前,那么只能自己恢复了。打开IDAPro.原创 2021-06-11 04:20:57 · 3026 阅读 · 0 评论 -
gsl有时正常执行,有时导致程序闪退
废话不多说,经过追踪源码,得到解决方案:// 在调用gsl函数之前执行下列代码gsl_set_error_handler_off();原创 2021-05-07 23:25:35 · 298 阅读 · 0 评论 -
AVFrame转QImage最佳方法
直接代码:直接写入QImage内存// 创建QImage img (pFrame->width, pFrame->height, QImage::Format_RGB888);uint8_t* dst[] = { img.bits() };int dstStride[4];// AV_PIX_FMT_RGB24 对应于 QImage::Format_RGB888av_image_fill_linesizes(dstStride, AV_PIX_FMT_RGB24, pFrame原创 2020-12-24 00:28:02 · 2726 阅读 · 0 评论 -
解决Invalid return value 0 for stream protocol
如果不使用文件作为输入,而是使用自定义的(内存)输入流,会看到此运行时警告。解决方法:在读取函数中如果输入流(内存数据),读取完毕返回-1。出现Invalid return value 0 for stream protocol的原因就是无有效数据时,返回的时0.int read(void *opaque, unsigned char *buf, int buf_size){ // 如果输入流(内存数据),读取完毕返回-1 // 如果还未到输入流结尾,则返回实际读取数据长度!..原创 2020-12-23 15:10:05 · 2121 阅读 · 1 评论 -
visual studio配置 新版 ffmpeg 开发环境
1、下载编译好的ffmpeg库https://ffmpeg.zeranoe.com/builds/选择想使用的库的类型。我这里使用动态库。需要下载Shared和Dev这2个2、打开visual studio,新建任意类型的C/C++工程3、配置工程属性追加工程的头文件路径:$(Dev_DIR)/include (下载的Dev项解压出来的include文件夹) 追加预编译宏:__STDC_CONSTANT_MACROS和__STDC_FORMAT_MACROS 追加库文件路..原创 2020-07-10 13:34:23 · 1624 阅读 · 0 评论 -
解决:warning LNK4217:本地定义的符号xxxx在函数 _main 中导入
解决方法:xxxx函数前的__declspec(dllimport) 去掉。出现原因:__declspec(dllimport) 必须用于从动态库对应的Lib中导入符号才会用到。如果是静态库或者直接源码链接,则必须把__declspec(dllimport)去掉,否则警告。...原创 2020-05-28 12:32:35 · 6033 阅读 · 0 评论 -
解决:C运行时检测到应用程序在堆内存末尾之外写入 CRT detected that the application wrote to memory after end of heap buffer
如果是程序内存越界访问,请自行管理越界。如果程序内存管理无误,那么请按下面方式解决:先清理,再重新编译。原因:在头文件中增加成员导致代码变化,编译器不会检测(编译器只检测cpp变化确定是否需要重新生成目标文件)。在头文件中增加程序会导致对象的内存增加,此时是不会重新编译的,除非也改变了需要编译的c/cpp文件。这就导致了这个运行时错误。通过重新编译工程,所有的目标文件重新生成,解决此问题。...原创 2020-05-11 11:38:04 · 1324 阅读 · 0 评论 -
socket中getoption的SO_ERROR和errno二者的区别?
对于同步socket,二者一样,使用errno更方便一些。对于异步socket,使用SO_ERROR,此值在真正的数据到来之前已经被设置,所以比errno更灵敏。以下是Unix网络编程的原话:If SO_ERROR is nonzero when the process calls read and there is no data to return, read returns–1...原创 2020-03-30 16:30:34 · 1315 阅读 · 0 评论 -
Modbus TCP 读写COIL(BOOL),Register(int/float)的c++代码
这几天做Modbus的PLC控制,实现代码:BOOL读取#define SIGN_ID (1)int readBool( unsigned short nAddr ){//读取COIL(BOOL)数据 //nAddr = 1; unsigned char buf[12]; unsigned char chHByte = HIBYTE(nAddr); unsigned ch...原创 2019-12-12 14:49:37 · 4211 阅读 · 1 评论 -
sqlite3_step失败?不返回SQLITE_OK,返回SQLITE_ROW(100)
根据sqlite API 文档,sqlite3_step函数从不返回SQLITE_OK,执行成功通常返回:SQLITE_ROW,表示当前的statement中包含一行的结果数据,SQLITE_DONE,表示已经遍历完成了所有结果集的行。...原创 2019-11-20 12:47:19 · 3833 阅读 · 0 评论 -
C/C++基本类型32位和64位字节大小
虽然用处不多,但在做32和64位的底层通信时可以用。32位sizeof(char)=1sizeof(short)=2sizeof(int)=4sizeof(long)=4sizeof(float)=4sizeof(double)=8sizeof(long long)=8sizeof(long double)=8sizeof(void*)=464位sizeof(...原创 2019-11-15 10:45:50 · 497 阅读 · 0 评论 -
排序算法的选择
没有一种算法显然是“最佳”算法。这取决于一系列因素。 首先,能将数据放入主内存吗?如果你能,那么需要依赖外部排序算法。这些算法通常基于快速排序(quicksort)和归并排序(mergesort),【译注:如果不能,根据使用的数据集的大小和类型,使用专用数据库加载数据或利用Google的BigQuery等基于云的服务】。 其次,输入数据的分布是什么样的?如果它大多数都是有序的,那...翻译 2018-11-06 10:09:27 · 1571 阅读 · 0 评论 -
如何检查,可执行程序,是debug模式?还是release模式?
Generally no.There hasn't a reliable way to do this with a native DLL file.Even you would be able to check what versions of system libraries a program is linked with and it's the debug version, c...原创 2018-11-03 13:22:22 · 2637 阅读 · 0 评论 -
debug 使用 release 的可执行程序
You can certainly pass STL objects across DLL boundaries but all involved dlls/exes must be compiled using the same compiler and the same compilation options.Remember that most of the STL code is i...原创 2018-11-03 13:06:43 · 465 阅读 · 0 评论 -
TCHAR in VC++
/* String functions */_tcscpy_s,_tcscat_s,_tcslen, _tcsnlen,_tcschr,_tcsdup,_tprintf, _tprintf_s, _stprintf, _stprintf_s /* String conversion functions */// Convert string to number...转载 2018-09-28 09:50:25 · 297 阅读 · 0 评论 -
Windows下的snprintf实现
_snprintf_s不会再最后加入\0,如果溢出返回-1.注意:微软在visual studio 2015中终于实现了snprintf函数。在以前的visual studio中,参考实现如下:#if defined(_MSC_VER) && _MSC_VER < 1900int vsnprintf(char *outBuf, size_t size, con...翻译 2018-09-06 21:30:36 · 1490 阅读 · 0 评论 -
进程间通信(IPC)模型的选择
When selecting your IPC you should consider causes for performance differences including transfer buffer sizes, data transfer mechanisms, memory allocation schemes, locking mechanism implementations,...转载 2018-11-06 12:19:54 · 1398 阅读 · 1 评论 -
C/C++释放内存大小,与内存监控得到的大小不同的原因
If you are viewing Task Manager size, it will give you the size of the process. If there is no "pressure" (your system has plenty of memory available, and no process is being starved), it makes no se...转载 2018-11-05 15:57:43 · 351 阅读 · 0 评论 -
MinGW读音
The name MinGW stands for Minimalist GNU for Windows. MinGW is also referred to as Mingw32 because it provides headers for the Win32 API. No standard has been decided for the pronunciation of MinGW. C...转载 2018-12-10 15:05:26 · 1655 阅读 · 0 评论 -
c/c++连接mysql5.7时,mysql_library_init,mysql_init等函数失败
罪魁祸首是mysql5.7提供了libmysqld.lib,libmysqld.dll这个库,它总是崩溃或返回NULL这种错误数值,甚至报错:This handle is already connected. Use a separate handle for each connection。正确使用:即使在debug模式下也应该用libmysql.lib,...原创 2019-03-15 15:47:55 · 3237 阅读 · 3 评论 -
libEvent关于多个客户端连接的处理
如果使用一个线程来处理每个传入的客户端连接,你将失去使用事件驱动模型的目的!应该设计代码,达到的目的:以便单个线程处理少量客户端连接,并随着并发连接数的增加而增加线程数。不应该:在接收客户端数据的IO的线程池中发送的数据的同事,进行繁重的计算工作。通常做法:将网络密集型IO的任务与执行任何CPU密集型计算分成两个独立的线程池模块。...原创 2019-04-02 20:07:32 · 1854 阅读 · 0 评论 -
OpenSSL1.1.1没有libeay.dll和ssleay.dll。
The complete explanation is that 1.0.x and 1.1.x do not have the same naming conventions for the generated libraries. OpenSSL 1.1.x has moved into what they call the “unified build system” and changed...转载 2019-06-22 13:53:33 · 6637 阅读 · 1 评论 -
固定管线的glBegin/glVertex/glNormal/glTexCoord/glColor等函数后调用glGetError返回GL_INVALID_OPERATION
原因:glBegin和glEnd之间只能调用顶点属性等相关函数,glGetError不可调用,GL_INVALID_OPERATION指的是glGetError操作无效。gBegin的文档说明如下(以微软的MSDN的GL1.1为例)You can use only a subset of OpenGL functions betweenglBeginandglend. The ...原创 2019-09-29 08:11:21 · 532 阅读 · 0 评论 -
MSDN:VC多线程程序
若要使用第一行运行时库 请忽略第2行的这些库单线程 (libc.lib,libc = library of C )libcmt.lib、msvcrt.lib、libcd.lib、libcmtd.lib、msvcrtd.lib多线程 (libcmt.lib , libcmt = library of c multithreading )libc.lib、msvcrt.lib、libcd.lib、转载 2015-09-14 16:42:28 · 1003 阅读 · 0 评论