English 中文(简体)
从档案系统中读取的数据与将数据直接编入方案
原标题:reading data from filesystem vs compiling the data directly into program
  • 时间:2012-04-10 04:00:54
  •  标签:
  • c
  • io

我有一份包含数据的文件(10-20MB),每个线是单一数据。

我有一个C方案,读到档案系统的档案,然后根据指挥线投入,它读到每个档案线,对每一行进行计算,以确定该分线是否应当归还,然后退回数据子集。

假设该方案在一开始便可读到整个档案,然后从记忆中直接投放。

如果我不是从档案系统读取数据,而是通过创建如下阵列,将数据直接编入方案,那么方案是否执行得更快?

char *dataArray[] = {"data1", "data2", "data3"....};

由于监督厅需要从档案系统读到整个双向,我感到,两种技术的执行时间是一样的,因为从档案系统读到都是高规律。 然而,没有人对此有更明确的想法?

最佳回答

将一切都定义为方案,肯定会更快。

You do not need the relatively slow "open" call for the data file and you don t need to move the data from the buffer to your storage.

这是1970年的一个通用优化轨道,此后每部节目/编码风格书都一直建议you不这样做。 实际业绩的提高是最低的,你在业绩方面获得的成绩是你无法维持和灵活。

如果你希望对此类问题作出可维持的快速选择,那么就看“mmap,该电话可直接向您的方案提供缓冲,并尽量减少数据流动。

问题回答

我怀疑执行时间的差别将很大,但从记忆利用的角度来看,将数据放在可执行(并适当限定其<条码>。

如果你读到一份档案中分配给你的记忆的数据(例如通过<代码>小型<>>/代码>)的10-20兆字,数据最初存在于两个记忆点:档案系统藏匿处和你的节目中。 如果记忆紧张,原复印件就可以丢弃,但后者在解放之前就永远保持记忆或交换。

另一方面,如果10-20兆克的数据是你方案形象的一部分(在可执行档案中),则数据将需上页,必要时可予以弃置,因为监督厅知道,如果需要,可以重新上页。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

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->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签