当我的应用程序加载时,我应该将什么加载到内存中?
我有使用序列化保存到文件系统的对象。当我加载应用程序时,我应该将所有对象加载到内存中还是仅加载存根(用于搜索功能)?
如果我只加载存根,那么我会在需要时从文件系统加载它们,然后将它们保留在内存中以便快速访问。
数量级是数百条记录而不是数千条。
您会推荐哪种方式?
I have objects I am saving to the file system using serialization. When I load the app, should I load all the objects into memory or just stubs (for searching capabilities)?
If I load just stubs, then I would load them from the file system when they are needed and keep them in memory after that for quick access.
The order of magnitude is hundreds of records not thousands.
Which way would you recommend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
按需要加载,并保留在内存中,不要浪费启动时间加载不会使用的东西。
您甚至可以尝试保留最请求的项目的记录,然后在启动时加载这些项目。
Load as required, and the keep in memory, dont waste starup time loading things that will not be used.
You might even try to keep a records of most requested items, and load those then on startup.
如果对象的大小和数量总是相当小,请在启动时加载它们。否则使用存根/代理。
If the size and number of objects will always be rather small, load them at startup. Use stubs/proxies otherwise.
这取决于。
如果您知道它永远不会超过数百,则将它们全部弹出到内存中。
如果您低估总数的可能性很小,请使用存根。
它还取决于记录的大小以及记录的更改频率。
It depends.
If you know it will never exceed hundreds, then pop them all into memory.
If there's a small chance you're underestimating the total, use stubs.
It also depends on the size of the records and how often they change.
这实际上取决于这些对象的使用场景。应用程序运行时是否经常使用它们?它们不经常使用吗?是否有些经常使用而另一些则不经常使用?
另外,您的应用程序将在其上运行的系统的预期资源基线是多少?您正在加载的物体是大还是小?即使只有几百个,如果它们都是非常大的物体,那也是一个重要因素。如果您需要一个低调的应用程序,那么按需加载似乎更合乎逻辑。
如果不了解更多关于预期用途和基线执行环境的信息,此类问题很难回答。它非常主观。
It would really depend on your usage scenarios for those objects. Are they all used frequently by the application when it is running? Are they used infrequently? Are some used frequently while others are used infrequently?
Also, what is the expected resource baseline of the systems your application will be running on? Are the objects you are loading large or small? Even if there are only a few hundred of them, if they are all very large objects, that would be a significant factor. If you need a low profile application, then loading on demand would seem more logical.
This kind of question is difficult to answer without knowing more about the expected usage and baseline execution environment. Its very subjective.
内存与性能。选择哪一个更重要(或者更确切地说,每一个有多重要)并相应地调整对象的缓存。
您甚至可以使用企业库缓存块,这可以加快您的速度执行。
Memory vs Performance. Choose which one is more important (or rather, how important each is) and adjust your caching of objects accordingly.
You could even use the Enterprise Library Caching Block, which could speed your implementation.