linux C++ 最快的读取中文文件(UTF-8)的形式
linux C++ 最快的读取中文文件(UTF-8)的方式
求 C++ 最快的读取中文文件(UTF-8)的方式
我试过全部load 然后转成wchar_t 不知道还有更快的方式没, 正确答案给500分 先连开2贴
void LoadFile(const char * file)
{
//setlocale(LC_ALL, "zh_CN.UTF-8");
std::ifstream t;
t.open(file); // open input file
t.seekg(0, std::ios::end); // go to the end
bufferLen = t.tellg(); // report location (this is the length)
t.seekg(0, std::ios::beg); // go back to the beginning
buffer = new char[bufferLen]; // allocate memory for a buffer of appropriate dimension
t.read(buffer, bufferLen); // read the whole file into the buffer
t.close(); // close file handle
}
void UTF_8ToUnicode(char *pSrc,int start, int end)
{
pSrc+=start;
int srcLen=end-start;
int maxLineCount=100000;
lines=(wchar_t **)malloc(sizeof(wchar_t *)*maxLineCount); // at most 100000 lines
linesLength=(int *)malloc(sizeof(int)*maxLineCount); // at most 100000 lines
setlocale(LC_ALL, "en_US.UTF-8");
//setlocale(LC_ALL, "zh_CN.UTF-8");
wchar_t* pDst=(wchar_t *)malloc(sizeof(wchar_t)*(srcLen+1));
wstrLen=mbstowcs (pDst, pSrc, srcLen);
}
------解决思路----------------------
可以研究看看https://github.com/glguy/utf8-string的做法。
------解决思路----------------------
在文件大小相同的前提下:
读刚读过的文件比头次读没读过的文件快
读转速快的硬盘上的文件比读转速慢的硬盘上的文件快
读没有磁盘碎片的文件比读有磁盘碎片的文件快
读文件不处理比边读边处理快
单线程从头到尾一次读文件比多线程分别读文件各部分快(非固态硬盘上)
读固态硬盘上的文件比读普通硬盘上的文件快
求 C++ 最快的读取中文文件(UTF-8)的方式
我试过全部load 然后转成wchar_t 不知道还有更快的方式没, 正确答案给500分 先连开2贴
void LoadFile(const char * file)
{
//setlocale(LC_ALL, "zh_CN.UTF-8");
std::ifstream t;
t.open(file); // open input file
t.seekg(0, std::ios::end); // go to the end
bufferLen = t.tellg(); // report location (this is the length)
t.seekg(0, std::ios::beg); // go back to the beginning
buffer = new char[bufferLen]; // allocate memory for a buffer of appropriate dimension
t.read(buffer, bufferLen); // read the whole file into the buffer
t.close(); // close file handle
}
void UTF_8ToUnicode(char *pSrc,int start, int end)
{
pSrc+=start;
int srcLen=end-start;
int maxLineCount=100000;
lines=(wchar_t **)malloc(sizeof(wchar_t *)*maxLineCount); // at most 100000 lines
linesLength=(int *)malloc(sizeof(int)*maxLineCount); // at most 100000 lines
setlocale(LC_ALL, "en_US.UTF-8");
//setlocale(LC_ALL, "zh_CN.UTF-8");
wchar_t* pDst=(wchar_t *)malloc(sizeof(wchar_t)*(srcLen+1));
wstrLen=mbstowcs (pDst, pSrc, srcLen);
}
------解决思路----------------------
可以研究看看https://github.com/glguy/utf8-string的做法。
------解决思路----------------------
在文件大小相同的前提下:
读刚读过的文件比头次读没读过的文件快
读转速快的硬盘上的文件比读转速慢的硬盘上的文件快
读没有磁盘碎片的文件比读有磁盘碎片的文件快
读文件不处理比边读边处理快
单线程从头到尾一次读文件比多线程分别读文件各部分快(非固态硬盘上)
读固态硬盘上的文件比读普通硬盘上的文件快