CSDN专家博客精华版

为人民服务!
  首页  :: 新随笔  :: 管理

.net中HashTable的最大容量

Posted on 2007-12-17 10:18  csdnexpert  阅读(132)  评论(0编辑  收藏  举报

网上一般说是没有限制 直到 内存溢出
我反编译了Hashtable.cs

其一个构造函数如下
public Hashtable(int capacity, float loadFactor)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if ((loadFactor < 0.1f) || (loadFactor > 1f))
            {
                throw new ArgumentOutOfRangeException("loadFactor", Environment.GetResourceString("ArgumentOutOfRange_HashtableLoadFactor", new object[] { 0.1, 1 }));
            }
            this.loadFactor = 0.72f * loadFactor;
            double num = ((float) capacity) / this.loadFactor;
            if (num > 2147483647)
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_HTCapacityOverflow"));
            }
            int num2 = (num > 11) ? HashHelpers.GetPrime((int) num) : 11;
            this.buckets = new bucket[num2];
            this.loadsize = (int) (this.loadFactor * num2);
            this.isWriterInProgress = false;
        }

 

可以看出capacity <0.72*2147483647*loadFactor (其中loadFactor 在0.1到1之间)
默认的loadFactor 为1f
故一般情况下 capacity < 1546188225.84

 

--
Be good @ Java & Dotnet.
Like OpenSource FrameWork,New Technique,especially Between different Platform.


“hill”编写:

> 最多能向Hashtable中插入多少个entry? 

 

http://www.microsoft.com/China/community/dgbrowser/zh-cn/default.mspx?&lang=zh&cr=CN&guid=&sloc=zh-cn&dg=microsoft.public.cn.dotnet.framework&p=1&tid=9874f917-9a87-4c48-b558-c2f33a26bec4



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1568384