vector扩容时候的move问题
先抛出问题代码,下面代码的这种情况下存在一个内部指针泄露问题,伴随vector扩容,ItemManager的function内部存储的指针会指向错误的Item对象 因此,下面的这个Item类,虽然是move constructable的,但是实际上因为使用了lambda + capture了this指针,等价于将内部的this外传,item manager没有随之处理这种move的情况。 ...
先抛出问题代码,下面代码的这种情况下存在一个内部指针泄露问题,伴随vector扩容,ItemManager的function内部存储的指针会指向错误的Item对象 因此,下面的这个Item类,虽然是move constructable的,但是实际上因为使用了lambda + capture了this指针,等价于将内部的this外传,item manager没有随之处理这种move的情况。 ...
准备看下asio的实现,就在win下搭建了。 准备仓库 git clone https://github.com/chriskohlhoff/asio.git 写CMakeLists.txt cmake_minimum_required(VERSION 3.10) project(StandaloneAsioExample) set(CMAKE_CXX_STANDARD 14)...
主要是在callback之后,当前发起cb的类可能在cb之后被销毁,但是在cb之后还有一些操作需要做,这个时候要么shared_ptr来保障,要么自定义一个guard配合unique ptr的deleter做保障 void ObjectA::Do() {} if (callback) { // NOTE: this callback may destroy the curren...
逆向工程intro Reverse Engineering For Everyone! consteval & constexpr & constinit consteval & constinit c++里的ub,编译器是怎么对待UB的 浅谈 C++ Undefined Behavior circular que Non-...
参考clang-tidy checkers 最后成品 UseColor: true Checks: > android-cloexec-*, android-comparison-in-temp-failure-retry, bugprone-*, clang-analyzer-*, modernize-*, -modernize-use-trailing...
如果hook了库函数,集成的时候对于运行时库的link顺序其实是有点要求的 计算机系统篇之链接(16):真正理解 RTLD_NEXT 的作用 Dangers of using dlsym() with RTLD_NEXT linux hook机制研究
leveldb在unix下编译很简单,不赘述。 之前看代码都是在linux下编译的,在win下看相关的实现的话,还是要配合编译一下的 本次编译环境 win == 11 cmake == 3.31.0 ninja == 1.12.1 clang == 18.1.0rc msvc == 2022 到手clone文件之后首先还是把third_party里的submo...
undefine behavior On the limits of time travel in the face of undefined behavior in C Undefined behavior can result in time travel (among other things, but time travel is the funkiest) What...
起因是看到这个Speeding up the insertion of a sorted (or mostly-sorted) key list into a std::map or other ordered associative container 代码对比 // normal for (auto&& v : source) { map.try_emplac...
自己手写代码应该是拍马都赶不上lib里的了,都用linux下x86的实现来看看. 实际上这些mem相关的操作,在现代cpu上都有rep ***这种指令。 memcpy 实现32和64的分离了,最后还是一套,代码在arch/x86/lib/memcpy_64.S和arch/x86/lib/memcpy_32.S里 // SPDX-License-Identifier: GPL-2.0 ...