我有一个巨大的C档案。在文件中,有一个巨大的结构(〜> 1百万行)。有没有办法使用其他内核并行编译此文件?
编辑:对不起,在查看了我的代码和我的问题之后,实际的巨型事情不是“struct”,而是结构数组......
答案 0 :(得分:3)
如果结构定义超过100万行,那么你可能运气不好。
但是如果你声明一个结构变量是一个结构类型的数组是多行(或者不是数组但只是一个非常大的结构),那么我建议将变量声明放在一个单独的.c文件中本身并在需要访问它的任何其他c文件中使用extern关键字。这样,它只需要在变化时重新编译。
例如,如果您有以下内容:
//Filename: onefile.c
struct _bigStruct{
int type;
char *name;
}bigStruct[] = {
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
{ 4, "Four" },
...
};
int someFunction(int j, int x)
{
if (j == bigStruct[x])
//do something
}
然后我会将其更改为以下内容:
//Filename: bigstruct.h
struct _bigStruct{
int type;
char *name;
};
和
//Filename: bigstruct.c
struct _bigStruct bigStruct[] = {
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
{ 4, "Four" },
...
};
和
//Filename: main.c
#include "bigstruct.h"
extern struct _bigStruct bigStruct[];
int someFunction(int j, int x)
{
if (j == bigStruct[x].type)
//do something
}