Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

memory management - .NET Collections and the Large Object Heap (LOH)

Are .NET collections with large number of items apt to be stored in the LOH?

I'm curious about List and Dictionary specifically. In my code, I store a large number (40k+) of relatively small objects (lets say 1k) in temporary Lists and Dictionarys for processing. Does the number of items in these collections increase the likelihood of being put on the LOH?

For list, assuming that List is implemented as a doubly linked list, then the number of elements should not increase the size of the actual List object, but I'd like to know for sure.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Objects will only be stored on the LOH if they are over 85,000 bytes. A large list (especially of structs) will often get allocated here.

However, Dictionary's are less likely, since they're storing an array of buckets, so unless the generate enough buckets so the array becomes >85000 bytes, it's unlikely. A list of 40k elements will be stored on the LOH, even if they're classes (since the object references in each element will cause the list to be 160k on x86, 320k on x64 systems). The individual elements will be on the standard heap, though, so will get compacted, etc.

If you are using a doubly linked list instead of a standard List, it is very unlikely that it will get stored on the LOH. Each element of the list will be small (just a single node with references to the next/previous nodes), so no single object will be >85k bytes.

For details on the LOH, this is a great blog entry.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...