如何将字节数组设置为最大 [英] How to set Byte array to Max
本文介绍了如何将字节数组设置为最大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这样声明一个字节数组
I want to declare a Byte array like this
Dim buffer() As Byte
但是我不知道数组的大小,如何设置最大值呢?
并且我需要设置一些东西,因为它给了我以后需要分配.
But I don''t know the size of the array SO how can I set it to take the max?
and I Need to set something since it give me it need to be assigned later on.
推荐答案
正如Mehdi所说,永远不要将缓冲区分配给最大大小! /> 在.NET中,任何单个对象的最大大小为2Gb,因此,字节数组的最大大小为2147483648字节.如果您继续分配而不需要实际使用的大量内存,则会非常非常快地降低计算机的爬网速度.
最初,将其定义为
As Mehdi says, never assign a buffer to the maximum size!
In .NET the maximum size of any single object is 2Gb, so the Max size of a bytes array is 2147483648 bytes. If you keep on allocating this much memory without actually needing it, you will slow your computer to a crawl very, very quickly...
Initially, define it as
Dim buffer() As Byte = nothing
,然后在知道需要多少字节后重新分配它.
And then re-assign it when you know how many bytes you need.
似乎您不知道创建数组时的大小.也就是说,您不应该使用数组.而是,使用通用类System.Collections.Generic.List
,请参见 http://msdn.microsoft.com/zh-CN /library/6sh2ey19.aspx [ ^ ].是的,您也可以使用数组,但是重新分配并不是一件好事.由于性能和其他原因,无法证明使用数组而不是列表.
—SA
It looks like you don''t know the array size at the moment of its creation. That said, you should not use array. Instead, use the generic classSystem.Collections.Generic.List
, see http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[^]. Yes, you can use array, too, but reallocation is not a very good thing. Due to performance and other reason, using array and not list cannot be justified.
—SA
这篇关于如何将字节数组设置为最大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文