[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]question about ArrayList.cs

From: Rhys Weatherley
Subject: Re: [DotGNU]question about ArrayList.cs
Date: Mon, 16 Sep 2002 08:47:43 +1000

Ian Fung wrote:

> in the Realloc function, making the new array for more elements looks like
> this:
> int newCapacity = (((count + n) + 31) & ~31);
> I assume the + 31 and & ~31 is some hack. I was just wondering why it needed
> to be there. is it something about bits being in the right place cause the
> way IL works etcetc? just wondering.

It rounds "count + n" up to the next multiple of 32.

Realloc is used to make "n" new entries in the array list.
This is normally called with "n == 1", which would cause
pretty bad memory performance.  So, I instead do realloc's
every 32 elements.

The "+ &" convention is a standard trick for rounding to a
power of 2.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]