.NET的MemoryStream - 我应该设置的能力? [英] .NET MemoryStream - Should I set the capacity?

查看:98
本文介绍了.NET的MemoryStream - 我应该设置的能力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的问题,我想的一切,我是后是最佳实践来声明一个新的MemoryStream

This is probably a really simple question, I think all that I am after is Best Practice for declaring a new MemoryStream

什么是以下2个样品之间的差异:

What is the difference between the following 2 samples:

MemoryStream的myStream =新的MemoryStream(0x10000处);

MemoryStream的myStream =新的MemoryStream();

显然,我知道第一实施例设置了流的初始容量。但是,这两种具有自动调整大小的容量。

Obviously, I know that the first example set the initial capacity of the stream. But, both of these have an automatically resizable capacity.

我有什么理由,我应该使用一种方法,而不是其他?

I there any reason why I should use one method as opposed to the other?

推荐答案

还有就是开销大小调整内存流有关。如果您知道或有合理的猜测,需要被存储在内存流预期的大小,你要使用的大小作为初始容量。否则,0则使用缺省大小并作为数据被加到将被调整。

There is overhead associated with re-sizing a memory stream. If you know or otherwise have a reasonable guess as to the expected size needed to be stored in the memory stream, you'll want to use that size as the initial capacity. Otherwise, the default size of 0 is used and will be resized as data is added.

这篇关于.NET的MemoryStream - 我应该设置的能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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