如何使用在C#中一个非常大的字典吗? [英] How can I use a very large dictionary in C#?

查看:189
本文介绍了如何使用在C#中一个非常大的字典吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#应用程序查找地图或字典,但预计到存储1-2 GB的数据。

I want to use a lookup map or dictionary in a C# application, but it is expected to store 1-2 GB of data.

有人可以告诉我是否仍然可以使用Dictionary类,或者如果我需要使用一些其他类的?

Can someone please tell if I will still be able to use dictionary class, or if I need to use some other class?

编辑:我们有一个使用Oracle数据库查询或查询对象的详细信息现有的应用程序。它是然而太慢,由于相同的对象得到反复查询。我当时的感觉,这可能是理想的使用查找地图这种情况下,提高了响应时间。不过,我很担心,如果规模将使它成为一个问题。

EDIT : We have an existing application which uses oracle database to query or lookup object details. It is however too slow, since the same objects are getting repeatedly queried. I was feeling that it might be ideal to use a lookup map for this scenario, to improve the response time. However I am worried if size will make it a problem

推荐答案

简答

是的。如果你的机器有结构足够的内存(以及程序和系统,包括操作系统的其他部分的开销)。

Yes. If your machine has enough memory for the structure (and the overhead of the rest of the program and system including operating system).

长的答案

您确定要?不知道更多关于你的应用程序,这是很难知道什么建议。

Are you sure you want to? Without knowing more about your application, it's difficult to know what to suggest.


  • 在哪里数据是从哪里来的?一份文件?文件?数据库?服务?

  • 这是一个缓存机制?如果是这样,你可以终止项目从缓存中一旦没有了一段时间访问?这样,您就不必保存所有的内存中的所有时间。

  • 正如其他人所建议的,如果你只是想存储大量数据,你可以只使用一个数据库?这样,你不必把所有的内存中的信息一次。随着索引,大多数数据库是优秀的执行快速检索。你可以这种方式与缓存结合起来。

  • 是将在内存只读的,还是会必须坚持回一些存储东西的时候改变的数据?

  • 可扩展性 - 你预计随着时间的推移将被存储在这个字典中的数据量会增加?如果是的话,你会碰到一个点,它是非常昂贵的购买,可以处理这个数据量的机器。你可能想看看一个分布式缓存系统,如果是这样的话(AppFrabric想到的),所以你可以水平扩展出(更多的机器),而不是垂直(一个真正的大贵点故障)。

  • Where is the data coming from? A file? Files? A database? Services?
  • Is this a caching mechanism? If so, can you expire items out of the cache once they haven't been accessed for a while? This way, you don't have to hold everything in memory all the time.
  • As others have suggested, if you're just trying to store lots of data, can you just use a database? That way you don't have to have all of the information in memory at once. With indexing, most databases are excellent at performing fast retrieves. You could combine this approach with a cache.
  • Is the data that will be in memory read only, or will it have to be persisted back to some storage when something changes?
  • Scalability - do you expect that the amount of data that will be stored in this dictionary will increase as time goes on? If so, you're going to run into a point where it's very expensive to buy machines that can handle this amount of data. You might want to look a distributed caching system if this is the case (AppFrabric comes to mind) so you can scale out horizontally (more machines) instead of vertically (one really big expensive point of failure).

更新

在海报的编辑来看,这听起来像缓存将这里很长的路要走。有很多方法可以做到这一点:

In light of the poster's edit, it sounds like caching would go a long way here. There are many ways to do this:


  • 简单的字典高速缓存 - 只是缓存的东西,它的要求

  • 内存缓存

  • 缓存应用程序块的我不是这个实现一个巨大的风扇,但是别人已经成功。

  • Simple dictionary caching - just cache stuff as its requested.
  • Memcache
  • Caching Application Block I'm not a huge fan of this implementation, but others have had success.

这篇关于如何使用在C#中一个非常大的字典吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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