Re: Strange code in Queue class in .NET framework

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
.



Relevant Pages

  • Re: Strange code in Queue class in .NET framework
    ... method of the generic Queue class in the .NET framework. ... public void Enqueue ... Except that it multiplies by 200L, so the length is converted to an Int64 before being multiplied, and no overflow is possible. ...
    (microsoft.public.dotnet.framework)
  • Re: Strange code in Queue class in .NET framework
    ... method of the generic Queue class in the .NET framework. ... public void Enqueue ... You can get whole the source code using netmassdownloader. ...
    (microsoft.public.dotnet.framework)
  • Strange code in Queue class in .NET framework
    ... I had a look into the source code of the Enqueuemethod of the generic Queue class in the .NET framework. ... public void Enqueue ...
    (microsoft.public.dotnet.framework)
  • Re: reference
    ... .NET Framework 1.1 ... >>> and when a combobox loads it fills the items with what evers in the file like this: ... >> public void Form1_Load(object sender, ...
    (microsoft.public.dotnet.languages.csharp)
  • Whidbey C# Generics/Iterators Question
    ... to break the compiler/runtime with my first Generics/Iterators attempt. ... reason I am posting it here is that I might be wrong, in which case, please ... public void Add ...
    (microsoft.public.dotnet.languages.csharp)