c++ - 为什么 Google Protobuf 在 Mac 上使用我的 cpp 应用程序执行
问题描述
我最近开始使用 clang 和 XCode 12 在 mac 上进行 C++11 开发,我真的很想更好地了解这个平台。
我正在测试在“空”C++ 程序中重载全局new
和delete
运算符,但我注意到使用全局替换运算符进行的 89new
个分配没有通过全局替换运算符解除分配delete
,这看起来像是内存泄漏。(也许不是,但为什么呢?)
在调试程序时,我发现这些分配都来自wireless_diagnostics::google::protobuf。
所以我的问题是:
- 什么是 Google protobuf,为什么它会出现在我的程序中?
- 为什么它会留下这些内存泄漏(或似乎是内存泄漏)?
- 有什么可做的吗?
这是代码:
#include <iostream>
size_t allocations = 0;
void* operator new(size_t size)
{
void* ptr = malloc(size);
if (!ptr) throw std::bad_alloc{};
allocations++;
return ptr;
}
void operator delete(void* ptr) noexcept
{
free(ptr);
allocations--;
}
int main(int argc, const char * argv[])
{
std::cout << allocations << std::endl;
return 0;
}
解决方案
(不能发表评论,所以发布为答案)
什么是 Google protobuf,为什么它会出现在我的程序中
我已将 google protobuf 用于序列化目的。这就像压缩数据(结构化),因此我们不必通过线路发送大量数据。
我不明白为什么它会出现在你的程序中。从长远来看,它可能与您的调试器有关?似乎正在完成无线诊断,所以我只能认为调试器正在这样做
你能分享一些调试器输出的截图或任何东西吗?这可能会更清楚地说明它。
推荐阅读
- javascript - 在 C/Rust 代码中为 Node-FFI 创建结构
- git - 如何在 git log 中以 %Y%m%d 格式打印提交日期?
- notifications - 如何使浏览器通知成为按钮中的可点击链接
- android - 如何在 Jetpack Compose 中更新画布上对象的位置变化?
- javascript - 打字稿:使用函数数组键入函数,该函数返回每个函数返回类型的数组
- css - 选择器右侧的 SASS (SCSS) 加号和 & 语法 ( + & ) 的含义?
- javascript - 光滑块中的未知背景颜色
- javascript - 当我尝试将数据放入这些对象时,使用 Vuex 操作获取数据对象并得到“未捕获(承诺)类型错误”
- python - 创建一个基于对象 Django 的 id 收集数据的超链接
- go - 为什么带有 GCM 的 AES-256 会在密文大小上增加 16 个字节?