English 中文(简体)
C++读/写文档快速跨平台算法
原标题:Fast cross platform algorithm for reading/writing file in C++

I want to pose a seemingly simple question that i can t find the answer nowhere. Is there a FAST modern algorithm for file input and/or output that can be compiled with all standard compliant C++ compilers and works for all operating systems without the requirement of external libraries ?

  1. i have found that the fastest way is to use memory mapped files, but that won t do cause we want the same piece of code working on all platforms
  2. we can t use apis like Win32 API cause that will make it platform specific
  3. i don t want to use c, i want the algorithm to be just pure c++ code with stl if feasible, not some ugly c with intermixed asm hack/trick
  4. frameworks or external libraries that don t belong in standart c++ shouldn t be used like wxWidgets, Qt, MFC etc.
  5. The big empasis of this whole question is that the algorithm is as FAST as possible, something along the lines of the speed of doing it with memory mapped files, even faster would be great but i know that is not possible

Have you ever seen something so crazy been researched by anyone else except me ? Is such an algorithm even possible ?

感谢任何建议

问题回答

限制如下:

能否将所有符合标准的C++汇编成册,并在不需要外部图书馆的情况下为所有操作系统工作?

您在标准图书馆档案中的职能受到很大限制。 Maybe POSIX功能(取决于你们重新考虑的“所有符合标准的C++汇编者”这一次。

如果这些限制对你来说足够快,你不得不开始放弃一些限制。

这与“algorithm”无关。

在把数据写到档案中时,你听从操作系统——记忆制文件是“最坏的”,因为你只是重写记忆书,而本组织则自行收回。 如果本组织不支持它,那么,你会在这方面退步,除非你想要执行自己的记忆层。

顺便说一句,PPOSIX有mmap,这样,如果你将 yourself限制在符合规则的系统中,你将重罚。

为了对“非洲顾问办公室的双重性”提出另一种观点,复制档案的大部分间接费用都由业务系统承担。 零敲碎打的档案需要更多的时间阅读。 没有任何通用或标准C++功能用于探测零散的档案。

C++中最快的方法:

std::ifstream in_file;
std::ofstream out_file;

out_file << in_file.rdbuf();

可以通过检索网站“copy file rdbuf等关键词查找更多细节。 上述碎块将复印件交给了监督厅,但可在所有平台上下载。 读到C++ i/o溪流后,你可以确定“缓冲”的大小,也可以使用自己的缓冲。

更快的复印件需要平台的具体功能,例如排雷部的转账。 使用透镜和多种缓冲器可以加快速度;但C++没有支持透镜(代谢是一种脱法标准,即支持read)。 一条透镜将读作缓冲器,另一个透镜是从缓冲器书写的。

几点:

  • This has nothing to do with algorithms.
  • Wanting to target ALL operating systems is not a very productive goal (and it s impossible
  • your code doesn t work on a particular platform until you ve tested it). Instead, I d focus on some set of operating systems that are feasible - say POSIX + Win32.
  • In that case, you can do memory mapping, for instance by implementing mmap() for Windows (on top of MapViewOfFile() etc -- the git source code has a mmap implementation for Windows if you need some inspiration)
  • If you can t use memory mapping, I d recommend using the normal C file api instead of C++ s file streams if performance is a big deal. Even though C++ s streams have the potential of higher performance for some operations, in practice it is quite a bit slower.
  • But, to get good performance, it can often be "good enough" just to make sure you re treating your data in a sane way. Read data sequentially, don t re-read, etc. Perfect is the enemy of good ;)

相应地在卷宗系统块大小的多个部分(或2个权力)中阅读,可能有所帮助。 之后,一栏一栏被忽略就收集了你的数据。 有一些地方的白皮书测试了不同区块的性能。 我希望我能再次找到。

您还可以尝试在档案中专门设计阅读栏目,而另一个在记忆中操纵数据(当然还有适当的同步)。 这使你能够在你再次阻止你在案卷上打听电话时使用邮联处理数据。

任何途径,如果你给这些想法以尝试,请让我们知道你是否注意到分歧。 基准测试的实际结果将令人感兴趣。

快速综合征(IO)一般将土壤分解成两件:

  1. Minimize data copying
  2. Minimize kernel/user context switching

大部分国际独立实体的技术都试图相互解决。 我知道的最快的跨平台编码是Perl IO系统。 我建议看。 来源:。 Perl hackers花了数十年的时间,使其国际交易日志尽可能快地进入尽可能多的平台。

其他招贴画是正确的,因为表演总是与通用性(交叉版)。

然而,总的来说,通过“展示”你的投入——利用校对读到相对较大的数据库并处理这些数据,你取得了最佳成果。

我知道,这是一个基本和一般性的答案,但是,正如你能够做到的那样具体,要么没有平台,要么更多地了解你重新处理的具体投入。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签