主页

C++引用计数智能指针的实现

写在前面 老师讲的很细, 可以参考: Mark shared_ptr; 总结一下面试常考知识点. #include <bits/stdc++.h> #include "../../utils/chrono.h" namespace base_version { template <typename T> class shared_ptr { T* _raw_ptr{}; std::atomic_size_t* _ref_count{}; void release() { if (_ref_count and _ref_count->fetc...

阅读更多

低版本内核使用gcc 12编译llvm项目

需要 python3.9 cmake3.21.1 注意这里 gcc-12 需要的 c 库版本是 2.33及更高. 如果不够的话也不行. 这里 c 库的位置也在 gcc-12 的 lib/ 里面 可能的 patch ///////// ./libcxx/include/__memory/aligned_alloc.h /////////加上这个函数 inline void* __aligned_alloc(size_t __alignment, size_t __size) { #if defined(_LIBCPP_HAS_ALIGNED_ALLOC) return ::aligned_alloc(__alignment, __size); #else ...

阅读更多

C++vector 的内存布局

写在前面 从vector 的内存布局角度看代码. #include <cstdint> #include <iostream> #include <vector> using namespace std; //typedef unsigned long uintptr_t; int main() { std::vector<int> v = {10, 20, 30}; v.reserve(10); // 设置 capacity 为 10 for (int i = 0; i < 3; ++i) { cout << (void*)&v[i] <...

阅读更多

Asan内存问题扫描

写在前面 -fsanitize=address,undefined -fsanitize-recover=all -fno-omit-frame-pointer -static-libasan   -fsanitize=address,undefined -fsanitize-recover=all -fno-omit-frame-pointer -static-libasan  去掉-O2 ASAN_OPTIONS="protect_shadow_gap=0,halt_on_error=0" ./xx ./conf/ 运行

阅读更多

Brpc学习(四)bthread 的 benchmark

写在前面 bthread 的原理 benchmark #include <bits/stdc++.h> #include <bthread.h> // #define use_bthread using namespace std; using namespace std::chrono; class TimeCost { public: TimeCost() : _start_time(std::chrono::high_resolution_clock::now()) {} void begin_time_point() { _start_time = std::chrono::high_resolution_clock::now(...

阅读更多

Total views.
您是Zorch的第 个小伙伴
Hits