用有限的内存排序 [英] Sort with the limited memory

查看:115
本文介绍了用有限的内存排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有X GB的可用RAM空间,并且我需要对大量数据进行排序(远远大于所有可用内存.它存储在硬盘驱动器上).您能给个提示,如何实现?

Suppose I have X GB of RAM space available and I need to sort a huge array of data (much greater the all the available memory. It's stored on the hard drive). Could you give a hint, how that could be accomplished?

推荐答案

您正在寻找外部排序. 在这些情况下,最大的开销通常是磁盘IO.因此,诀窍是使用一种最小化磁盘IO的算法. 通常的方法是将适当的大块读取到内存中,对这些块进行排序,然后将它们保存回磁盘,然后合并排序后的块.

You are looking for external sorting. The largest cost in these scenarios is often disk IO. So the trick is to use an algorithm that minimises disk IO. The usual approach is to read suitably large chunks in to memory, sort those chunks, saving them back to disk, then merge the sorted chunks.

搜索外部排序"或排序合并"以及您选择的技术应会带来不错的结果.

A search for "external sorting" or "sort merge" and your technologies of choice should give some good results.

这篇关于用有限的内存排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆