【问题标题】:Why is Google Protobuf executed with my cpp app on mac为什么 Google Protobuf 在 Mac 上使用我的 cpp 应用程序执行
【发布时间】:2021-11-18 21:14:42
【问题描述】:

我最近开始在 mac 上使用 clang 和 XCode 12 进行 C++11 开发,我真的很想更好地了解这个平台。

我正在测试在“空”C++ 程序中重载全局 newdelete 运算符,但我注意到使用全局替换 new 运算符进行的 89 个分配没有通过全局替换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;
}

【问题讨论】:

    标签: c++ memory-management memory-leaks protocol-buffers clang++


    【解决方案1】:

    (不能发表评论,所以发布为答案)

    什么是 Google protobuf,为什么它会出现在我的程序中

    我使用 google protobuf 进行序列化。 这就像压缩数据(结构化),因此我们不必通过网络发送大量数据。

    我不明白为什么它会出现在你的程序中。 从长远来看,它可能与您的调试器有关? 看来无线诊断正在进行中,所以我只能认为调试器正在这样做

    你能分享一些调试器的输出截图吗?这可能会更清楚地说明它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 2011-07-23
      • 2013-07-19
      • 1970-01-01
      相关资源
      最近更新 更多