哪些数据结构读取/存储500个对象 [英] What data structure for reading / storing 500 objects

查看:131
本文介绍了哪些数据结构读取/存储500个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序启动时,我需要从一个XML页面加载约500对象,如:

When my application starts I need to load about 500 objects from an xml page, like this:

<object>
<name>objectname</name>
<info>info</info>
<info2>info</info2>
<info3>info</info3>
<info4>info</info4>
<alias>false</alias>
</object>

现在我想这个存储设备上,希望能读会更快。目前我使用的的ObjectOutputStream 写的对象。

Now I want to store this on the device, hoping the reading will be faster. Currently I use an ObjectOutputStream to write the objects.

private static void write(ArrayList<MyObject> objects, String fileName, Context context) {
        final File cacheDir = context.getCacheDir();
        final File objectsFile = new File(cacheDir.getAbsoluteFile() + File.separator + fileName);

        FileOutputStream fos = null;
        ObjectOutputStream oos = null;
        boolean keep = true;

        try {
            fos = new FileOutputStream(objectsFile);
            oos = new ObjectOutputStream(fos);

            oos.writeObject(objects);
        } catch (Exception e) {
            e.printStackTrace();
            keep = false;
        } finally {
            try {
                if (oos != null)
                    oos.close();
                if (fos != null)
                    fos.close();
                if (keep == false)
                    objectsFile.delete();
            } catch (Exception e) {
            }
        }
    }

这是不是一个非常快速的解决方案,可以阅读大约需要10-15秒。我展示在ListView的对象,所以需要一次读取的所有对象。

This is not a very fast solution, reading can take about 10-15 seconds. I'm showing the objects in a listview, so all objects need to be read in at once.

任何想法?

推荐答案

我觉得这种存储数据的最佳方法是在数据库中(的看到这里)。

I think the best method to store such data would be in a database (see here).

解析一次并存储在数据库中的信息(为每个属性一列)。它应该是pretty快速从数据库中检索500个记录:)

Parse once and store the information in the database (one column for each attribute). It should be pretty fast to retrieve 500 records from the database :)

这篇关于哪些数据结构读取/存储500个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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