首页 > 解决方案 > 为什么这个 C++ 结构(具有固定长度数组)会导致巨大的编译时间

问题描述

我在静态 c/c++ 库中有这个 c 结构:

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_NUMBER_EXPECTATIONS 2048

struct MIRExpectation
{
    uint32_t id;
    uint32_t note;
    double   time;
    double   duration;
};

typedef struct MIRExpectation MIRExpectation;

struct MIRScheduledExpectation
{
    double         musicalReferenceTime;
    MIRExpectation expectation;
};

typedef struct MIRScheduledExpectation MIRScheduledExpectation;

struct MIRTask
{
    MIRScheduledExpectation expectations[MAX_NUMBER_EXPECTATIONS];
};

typedef struct MIRTask MIRTask;


#ifdef __cplusplus
}
#endif

并在链接 c/c++ 库的 swift 应用程序中像这样使用它:

var mirgaTask = MIRTask()

现在,当我快速使用这一行时,这Compile Swift Source Files一步需要很长时间。

有什么想法吗?快速编译器在做什么?它是否在某种程度上将固定大小的数组快速映射到固定大小的数组?

编译器版本:

Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode11.7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

标签: c++swiftstruct

解决方案


推荐阅读