小编L.A*_*ida的帖子

C++(gcc/g ++)两个巨大的字符串数组需要很长时间才能编译

对于用C++编写的程序,我需要两个包含数据的庞大字符串数组.

它们在头文件中定义如下:

#include <string>
static const string strdataA[30000]={"this is the first line of the data",
    "the second line of data",
    "other stuff in the third line",
Run Code Online (Sandbox Code Playgroud)

向下

    "last line."};
//second array strings
static const string strdataB[60000]={"this is the first line of the data",
    "the second line of data",
    "other stuff in the third line",
Run Code Online (Sandbox Code Playgroud)

向下

    "last line."};
Run Code Online (Sandbox Code Playgroud)

但是当我用g ++编译它时,我需要很长时间才能完成它.它还使用大约2 GB的虚拟内存.所以我注释掉了strdataB [],然后程序确实编译了,但是很长一段时间后仍然如此.可执行文件只有大约8 Mb并且工作正常.

我该怎么做才能加快编译过程?我不介意我是否必须更改代码,但我不想使用外部文件加载.我想要一个数组,因为它在程序中对我来说非常好.

我在网上读到"静态const"应该做的伎俩,但我从经验中学到它没有.

非常感谢您的任何建议!

c++ arrays string static const

7
推荐指数
1
解决办法
890
查看次数

标签 统计

arrays ×1

c++ ×1

const ×1

static ×1

string ×1