Jeroen Mostert
3/2/2008 5:35:00 PM
Erik Funkenbusch wrote:
> On Sun, 02 Mar 2008 17:54:03 +0100, cody wrote:
>
>> Hi folks, I had a look into the source code of the Enqueue(T item)
>> method of the generic Queue class in the .NET framework.
>>
>>
>> public void Enqueue(T item)
>> {
>> if (this._size == this._array.Length)
>> {
>> int capacity = (int) ((this._array.Length * 200L) / 100L);
>> ..
>>
>>
>> isn't the last line the same as "int capacity = _array.Length * 2" ?
>> Did I miss something?
>
> One possible reason for this might be as a sort of clever "high bandpass
> filter". Meaning that if _array.Length * 200 > the amount an int can hold,
> it will throw an exception, thus limiting the allocation size to 1/200th of
> the size of an int.
Except that it multiplies by 200L, so the length is converted to an Int64
before being multiplied, and no overflow is possible.
You have to keep in mind that this is not the source, really, it's
decompiled IL. The actual source may have looked more sensible.
--
J.