在一个比较大的文件头部添加数据,请问怎么实现?
文件大小上M字节。
要求:效率最高。
欢迎大家来讨论!
文件大小上M字节。
要求:效率最高。
欢迎大家来讨论!
解决方案 »
- 在documentComplete里能够获得通过settime来动态写入的元素吗?
- 在对话框中放WebBrowser,如何判断文件(网页)加载完毕
- 高效TCP服务器选择
- 关于WSASend的疑惑,请高手进来讨论!
- 请问为什么调用Crecordset.open方法2次,会出错
- 请问如何实现闪烁标题栏??
- 求救:分包发送接收时不时出现15-16ms延时
- 调试时遇到了问题,请求帮忙!报错信息见内容
- 请问如何打开对话框选择文件夹
- 【求助】如果在DLL里面获取被注入进程的主线程ID
- 高分求peter norton《MFC开发Window95/NT应用程序》的配书源代码。
- C++里面的简单问题.不明处请指教.在线等待中!
然后用dos的copy命令把两个文件接起来
Efficient means of reading large text files CStringFile Class --------------------------------------------------------------------------------This article was contributed by Frank Driesens.Environment: VC5/6, NT4, CE 2.11Once upon a day I was asked to write an application which could do some serious filtering, on a ';' seperatedfile which held multiple collumns. The initial file was about 7 Mb in size, so I had to create a program which could read a file, process the read lines and produce a new output file.
So you think, what's the big deal ?
When I wrote that program, a pentium 133 was considered a fast PC. As far as I knew, there where no generic (Microsoft provided ??) solutions for a simple task as reading text from a file. So I build my own textfile reading class.
This brings me to the part which I found most interesting, the first version of this filtering program, did the job in several seconds.
So how come the thing worked so fast ? By the optimal manner of reading a text file.The StringFile class itself consists of 2 loops. One loop is for filling a read buffer, and the other loop is used for reading a line from this buffer. The effect of these loops is that when the file is read, its is done by reading 2k of data per turn. Further processing (finding where any given line starts and when it stops) is done inside memory, not on disk. And, as you can probably known, memory is faster then disk...so there's my explanation for the speed of the filter program.
After some fiddling around with this class I decided to post this, so that everyone can enjoy this piece of code. This sample show just how easy this thing works, open, read and close. What do you want more ?? #include "StringFile.h"BOOL ReadTextFile(LPCSTR szFile)
{
CStringFile sfText;
CString szLine;
BOOL bReturn = FALSE; // When the given file can be opened
if(sfText.Open(szFile))
{
// Read all the lines (one by one)
while(sfText.GetNextLine(szLine)!=0)
{
printf("%s\r\n",szLine); //And print them
}
sfText.Close(); // Close the opened file
bReturn = TRUE; // And say where done succesfully
}
return bReturn;
}Some benching (trying to find optimum blocksize for reading) gave me the following results:
This shows that the optimum size for this piece of code lies around 2k blocksize. Increasing this blocksize doesn't speedup reading, the only thing speeding up the read actions is probably improving the used code.Downloads
Download source - 3 Kb
History
Date Posted: April 2, 2000http://www.codeguru.com/files/StringFile.zip
新建一个文件,写入头,再把用xcopy考到一起。
http://codeguru.earthweb.com/tools/QuickSplit.shtml
一个朋友说了个办法,觉得不错,与大家共享
先创建一个新文件,写入要添加的数据,
然后将此文件映射CreateFileMapping,其第四个参数dwMaximumSizeLow设为此文件大小加要添加的文件大小,然后将要添加的文件也映射入内存,起始地址为刚创建的文件尾,用MapViewOfFileEx可实现。
这样,两个文件就衔接起来了,只要设置一下前一个文件指针即可,SetEndOfFile
然后UnMapViewOfFile就可以了。