Posted onIn杂记Word count in article: 1.4kReading time ≈5 mins.
I recently went looking for an analytics tool for an app I’m developing. There are plenty of options out there, but most are either too heavyweight or raise privacy concerns. After some research, Aptabase caught my eye — it’s privacy-first, uses no unique user identifiers, fully complies with GDPR/CCPA, comes with a clean and intuitive dashboard, and offers over 10 SDKs covering most major frameworks. Best of all, it supports self-hosting, so your data stays entirely under your control.
The official self-hosting repository makes it look simple — just clone, tweak a few configs, run docker compose up -d, and you’re done. But the actual deployment process had quite a few gotchas, and many others in the Issues have run into similar problems. Here’s what I learned, hoping it saves you some trouble.
技术书籍偏 C++ 以及一些底层的技术,英文为主。 选英文版主要原因有两个吧,一是有些书没有中文版,即便有,翻译的也很晦涩难懂,我倒不怪罪译者的水平,技术书籍确实比较难翻译得平易近人。(打比方说我比较敬仰的 C++ 骨灰级程序员 侯捷老师 的技术水平肯定是一流的,但是翻译的书也是很晦涩,可读性比较..)
Effective Modern C++ Scott Meyer 著作,每次读都会有新的收获,技术点讲的非常的细,比如关于 std::move 和 universal reference 就花了一章来介绍,各种想不到的 case. C++ 真的是了解的越多,就发现不了解的更多。 建议阅读英文版。
All member functions (including copy constructor and copy assignment) can be called by multiple threads on different instances of shared_ptr without additional synchronization even if these instances are copies and share ownership of the same object.
If multiple threads of execution access the same instance of shared_ptr without synchronization and any of those accesses uses a non-const member function of shared_ptr then a data race will occur; the shared_ptr overloads of atomic functions can be used to prevent the data race.
intmain(int argc, char *argv[]){ auto test = std::make_shared<SomeType>(); std::vector<std::thread> operations; for (int i = 0; i < 10000; i++) { std::thread([=]() mutable { //<<-- auto n = std::make_shared<SomeType>(); test.swap(n); }).detach(); }
intmain(int argc, char *argv[]){ auto test = std::make_shared<SomeType>(); std::vector<std::thread> operations; for (int i = 0; i < 10000; i++) { std::thread([&]() mutable { // <<--- auto n = std::make_shared<SomeType>(); test.swap(n); }).detach(); }
Posted onInC++
,
模版元编程Word count in article: 2.1kReading time ≈8 mins.
C++ 中使用 std::shared_ptr 智能指针不当有可能会造成循环引用,因为 std::shared_ptr 内部是基于引用计数来实现的, 当引用计数为 0 时,就会释放内部持有的裸指针。但是当 a 持有 b, b 也持有 a 时,相当于 a 和 b 的引用计数都至少为 1,因此得不到释放,RAII 此时也无能为力。这时就需要使用 weak_ptr 来打破循环引用。