序列化一个非常大的列表 [英] Serializing a very large list

查看:88
本文介绍了序列化一个非常大的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库查询获取了大量数据,而我正在制作它们的对象。我终于有了这些对象的列表(大约1M对象),我想将其序列化到磁盘供以后使用。问题是它几乎不适合在内存中并且将来不适合,所以我需要一些系统来序列化说第一个100k,下一个100k等;并且还以100k的增量读回数据。

I'm gettint a large amount of data from a database query and I'm making objects of them. I finally have a list of these objects (about 1M of them) and I want to serialize that to disk for later use. Problem is that it barely fits in memory and won't fit in the future, so I need some system to serialize say the first 100k, the next 100k etc; and also to read the data back in in 100k increments.

我可以制作一些明显的代码来检查列表是否变得太大然后将它变成文件'list1' ,然后'list2'等但也许有更好的方法来处理这个?

I could make some obvious code that checks if the list gets too big and then wirites it to file 'list1', then 'list2' etc but maybe there's a better way to handle this?

推荐答案

你可以通过列表,创建一个对象,然后立即将其提供给 ObjectOutputStream 将它们写入文件。

You could go through the list, create an object, and then feed it immediately to an ObjectOutputStream which writes them to the file.

这篇关于序列化一个非常大的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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