Array.Clear vs List<>.Clear

P

Peter Duniho

Ben said:
It doesn't need to zero each pointer, just make the whole mess unreachable.
It does that by clearing its reference to the entire array of pointers --
O(1), not O(N).

Well, Clear() doesn't affect the Capacity of the list. So at the very
least, it has to replace that array with a new one. And the new one has
to be cleared. It may have been pre-cleared by the memory manager (I
don't know how the default values work...the built-in value types all
have a 0-equivalent default value, so I suppose the memory manager could
take advantage of that), but assuming the capacity remains the same,
somewhere at some point in time some code had to go through and zero out
all of the elements of that array.

I note in the documentation: "This method is an O(n) operation, where n
is Count":
http://msdn2.microsoft.com/en-us/library/dwb5h52a.aspx

Sounds to me as though List.Clear() definitely does clear each item in
the array.

Pete
 
P

Peter Duniho

Ben said:
The 2GB limit doesn't apply to x64.

My understanding is that even on 64-bit, .NET has a 2GB limitation, or
at least a 2^32 element count limitation.

Has this changed? Is there a true 64-bit implementation of .NET
available now?

Pete
 
B

Ben Voigt [C++ MVP]

Peter Duniho said:
My understanding is that even on 64-bit, .NET has a 2GB limitation, or at
least a 2^32 element count limitation.

Well, 2^32 elements would be considerably better than the 2GB virtual
address limit.... but the information Jon posted shows there is still a
limit, although this time more artificial.
 
W

Willy Denoyette [MVP]

Peter Duniho said:
My understanding is that even on 64-bit, .NET has a 2GB limitation, or at
least a 2^32 element count limitation.

Has this changed? Is there a true 64-bit implementation of .NET available
now?

Pete


No, the (current) object size limit is not expressed in elements, it's
simply 2^31 bytes. (~2GB). The means that the largest array in n .NET is
currently 2^31 bytes, or (2^31)/4 int's or 2^31)/8 long's, etc...
A true 64 bit version is available since V2, but the bitness has nothing to
do with the object size limits imposed by the CLR.


Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top