简体   繁体   English

什么是C#中的超大型对象?

[英]What are exaclty Large Objects in C#?

Can I call an array of 1 million integers as large object? 我可以将一百万个整数的数组称为大对象吗? Or one instance of that object should be > 85 KB to be considered as large object? 还是该对象的一个​​实例应该大于85 KB才能被视为大对象?

If I make an array like int[1000000]. 如果我创建一个像int [1000000]这样的数组。 This whole object with each member is treated as one object with size > 85 KB. 每个成员的整个对象都被视为一个大小大于85 KB的对象。 right? 对?

If I have a class X {int i; 如果我有X类{int i; string j} .. then List having count > 100000. Will this be saved to LOH? 字符串j} ..然后列表计数>100000。这将保存到LOH吗?

Basically what I mean is if the size of an object like Class X is say 8.6KB and I make a datastructure like List myList. 基本上,我的意思是说是否像X类这样的对象的大小为8.6KB,并且我是否创建了像List myList这样的数据结构。 Then if the list count is 9 then it is not LO but if it has count 10 then it is? 那么如果列表计数是9,那么它不是LO,但是如果列表计数是10,那么它是LO?

I want a last answer(almost go all the answers): Now I know that array is a collection of pointers of 8 bytes. 我想要一个最后的答案(几乎所有答案都可以):现在我知道数组是8个字节的指针的集合。 So an array to be Large object it should have 85000/8 number of elements or more. 因此,作为大对象的数组应具有85000/8或更多的元素数。 Is that correct? 那是对的吗?

Any object larger than 85,000 bytes is considered to a large object and is treated differently during garbage collection. 任何大于85,000字节的对象都被视为大对象,并且在垃圾回收期间将被不同地对待。 An array can itself be over 85,000 bytes large if all its references (aka pointers) make up that amount. 如果数组的所有引用(即指针)组成该数组,数组本身可以超过85,000个字节。

In case of arrays the actual count is not made up of the size of the objects but their references. 对于数组,实际计数不是由对象的大小组成,而是由它们的引用组成。 Let's say you have an array of Customer, and let's assume that a Customer has 3 integers, each 8 bytes in size, and each reference is also 8 bytes in size. 假设您有一个客户数组,并假设客户有3个整数,每个整数8个字节,每个引用也都是8个字节。 Then an array of 10 Customers actually takes up 80 bytes, not 240. The 24 bytes of each Customer are separate objects. 然后,由10个客户组成的数组实际占用80个字节,而不是240个字节。每个客户的24个字节是单独的对象。

See this article for further information, and refer also to the Large Object Heap Improvements in .NET 4.5 . 有关更多信息,请参见本文 ,另请参阅.NET 4.5中大对象堆改进

如果您在垃圾回收的上下文中询问,那么85 KB将是一个大对象,因为大对象会立即标记为第2代对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM