[Mono-devel-list] PATCH: Lazily allocate ArrayList buffers
bmaurer at users.sourceforge.net
Sun Feb 15 01:10:45 EST 2004
Attached is a patch that makes ArrayLists allocate their buffers only on
the first addition to the list. For example the following code:
ArrayList ar = new ArrayList ();
ar = null;
will not allocate an object .
Running the profiler on a few applications, it seems that the patch has
some effect. One notable example is MonoDevelop where it prevented 2/3
of the allocations of arraylists.
It seems that MS implements this behavior in the v2 framework. Using a
beta of the code, I ran:
ArrayList ar = new ArrayList ()
It returned 0. This seems to indicate that the capacity (which is the
size of the array) is zero until something has been added.
For my patch, I made it so that the outside behavior would not change,
the code fudges having a 16 capacity when the list is empty. Our nunit
tests probe for this case. However, I wonder if we really should do
The nunit tests pass after the patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2341 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040215/ecd6a025/attachment.bin
More information about the Mono-devel-list