对于MacOS / X 10.8.x中不推荐使用的Carbon函数,该怎么办?

Jer*_*ner 5 c macos-carbon deprecated osx-mountain-lion

我有一个已经存在了一段时间(超过10年)的C ++代码库,并且可以正常运行,但是我注意到当我在OS / X 10.8.x(Mountain Lion)下对其进行编译时,编译器会发出关于以下内容的弃用警告:它调用的一些Carbon函数:

../system/SetupSystem.cpp:575:44: warning: 'UpTime' is deprecated: first
  deprecated in OS X 10.8 [-Wdeprecated-declarations]
../system/SetupSystem.cpp:575:22: warning: 'AbsoluteToNanoseconds' is
  deprecated: first deprecated in OS X 10.8 [-Wdeprecated-declarations]
../system/SystemInfo.cpp:249:25: warning: 'MPProcessors' is deprecated: first deprecated in OS X 10.7 [-Wdeprecated-declarations]
Run Code Online (Sandbox Code Playgroud)

我想将此代码库升级到Apple认可的新工作方式(从而避免警告和将来(如果Apple最终删除这些功能时)的麻烦),但是我不知道新标准是什么。我浏览了developer.apple.com上的OS / X文档,但是缺少搜索技能或者缺少他们的文档,因为我发现这些功能几乎没有,也没有替代品。

我有一些具体问题:

  1. 为什么不推荐使用这些功能?
  2. 我应该调用什么功能呢?
  3. 是否有一些我不知道的秘密文档存储库可以为我回答这些问题?

Jer*_*ner 2

我找到了上面列出的功能的可用替代品:

  1. UpTime() 可以替换为对 mach_absolute_time() 的调用,详细信息请参见此处
  2. AbsoluteToNanoseconds() 可以用一些数学代替,如上面的链接所示。
  3. MPProcessors 可以通过调用 host_info() 来替换,如下所示:
#include <mach/mach_host.h>

mach_msg_type_number_t infoCount = HOST_BASIC_INFO_COUNT;
host_info(gHostPort, HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
int numProcessors = hostInfo.avail_cpus;