Any boxing issues with a big list of booleans? Any alternatives?
I need a list of booleans (size anywhere from 200 to 开发者_开发知识库200k). If i use System.Collections.Generic.List<bool>
I'm going to suffer from serious boxing issues (correct me if I'm wrong).
What are the alternatives? (of course i know i can use a boolean array but i need to be able to add and remove things easily from the array)
Edit:
another question i have is (similarly to the top question,) what if i need a list of integers, what solutions do i have?
According to this:
http://www.dijksterhuis.org/exploring-boxing/
The generic list completely removes the boxing issues.
Also, I've held that many ints, strings, etc in a List many times with no performance issues. In fact, I've held up to 1,000,000 before without a problem.
Try the BitArray
class: http://msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx
Edit: If space is your concern, the BitArray
is 8 times smaller than a List<bool>
. A BitArray
will use one bit per boolean, whereas a List<bool>
will use 8 bits per boolean.
精彩评论