在给定内存限制的情况下对具有大量数据的文件进行排序 [英] Sort a file with huge volume of data given memory constraint
本文介绍了在给定内存限制的情况下对具有大量数据的文件进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
积分:
- 我们每天同时处理数千个平面文件.
- 内存限制是一个主要问题.
- 我们为每个文件进程使用线程.
- 我们不按列排序.文件中的每一行(记录)都被视为一列.
做不到:
- 我们不能使用 unix/linux 的排序命令.
- 我们不能使用任何数据库系统,无论它们有多轻.
现在,我们不能只加载集合中的所有内容并使用排序机制.它会吃掉所有内存,程序会出现堆错误.
Now, we cannot just load everything in a collection and use the sort mechanism. It will eat up all the memory and the program is gonna get a heap error.
在这种情况下,您将如何对文件中的记录/行进行排序?
In that situation, how would you sort the records/lines in a file?
推荐答案
看起来你要找的是外部排序.
基本上,您首先对小块数据进行排序,将其写回磁盘,然后遍历这些数据以对所有数据进行排序.
Basically, you sort small chunks of data first, write it back to the disk and then iterate over those to sort all.
这篇关于在给定内存限制的情况下对具有大量数据的文件进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文