垃圾收集固定阵列! [英] Garbage collectable pinned arrays!

查看:51
本文介绍了垃圾收集固定阵列!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


如果固定阵列是垃圾,那将会很棒。

可收藏。这将大大减少托管和非托管内存的来回复制量。

我想不出一个原因,为什么GC不应该允许

这个。


如果内存已经可以分配,那也会很棒

固定:

double [] array = new pinned uninitialized double [500];


未初始化意味着它未设置为零,因此

节省GC压力高的处理能力。


谢谢!

Atmapuri

Hi!

It would be great, if the pinned arrays would be garbage
collectable. This would greatly reduce the amount of copy
back and forth the managed and unmanaged memory.
I cant think of a single reason, why the GC should not allow
this.

It would be also great, if the memory could already be allocated
as pinned:

double[] array= new pinned uninitialized double [500];

where uninitialized would mean that it is not set to zero, thus
saving processing power where GC pressure is high.

Thanks!
Atmapuri

推荐答案

2月11日晚上11:51,Atmapuri < janez.makov ... @ usa.netwrote:
On Feb 11, 11:51 pm, "Atmapuri" <janez.makov...@usa.netwrote:

嗨!


如果是固定阵列将是垃圾

可收集。这将大大减少托管和非托管内存的来回复制量。

我想不出一个原因,为什么GC不应该允许

这个。


如果内存已经可以分配,那也会很棒

固定:

double [] array = new pinned uninitialized double [500];


未初始化意味着它未设置为零,因此

节省GC压力高的处理能力。
Hi!

It would be great, if the pinned arrays would be garbage
collectable. This would greatly reduce the amount of copy
back and forth the managed and unmanaged memory.
I cant think of a single reason, why the GC should not allow
this.

It would be also great, if the memory could already be allocated
as pinned:

double[] array= new pinned uninitialized double [500];

where uninitialized would mean that it is not set to zero, thus
saving processing power where GC pressure is high.



据我所知,pinning是* reference *的一个属性,而不是对象本身的
。当在调用堆栈的任何地方有一个固定的

引用时,该对象被固定。


因此,它对于一个没有意义固定物体是垃圾

收藏品。无论如何,这个物体都不能被视为垃圾。

你仍然持有它的引用,一旦你放弃了

的最后一个参考,它'不再固定。


我不明白为什么你甚至希望它实际上是收藏品。

固定点是让非托管代码访问对象,而不用担心GC会移动它。但收集物品和

让它的记忆用于其他东西就像移动它一样危险!


Jesse

As I understand it, pinning is an attribute of the *reference*, not
the object itself. The object is pinned when there''s a pinning
reference to it anywhere on the call stack.

Thus, it doesn''t make sense for a pinned object to be garbage
collectible. The object can''t be considered garbage anyway while
you''re still holding a reference to it, and once you let go of the
last reference, it''s no longer pinned.

I don''t see why you''d even want it to be collectible, actually. The
point of pinning is to let unmanaged code access the object without
worrying that the GC will move it. But collecting the object and
letting its memory be used for something else is just as dangerous as
moving it!

Jesse


2月12日凌晨3:55,Atmapuri < janez.makov ... @ usa.netwrote:
On Feb 12, 3:55 am, "Atmapuri" <janez.makov...@usa.netwrote:

嗨!
Hi!

据我所知它,pinning是* reference *的一个属性,而不是对象本身的
。当在调用堆栈的任何位置有一个pinning

引用它时,该对象被固定。
As I understand it, pinning is an attribute of the *reference*, not
the object itself. The object is pinned when there''s a pinning
reference to it anywhere on the call stack.


因此,固定物体是无用的是没有意义

可收藏。无论如何,这个物体都不能被视为垃圾。

你仍然持有它的引用,一旦你放弃了

的最后一个参考,它'不再固定。
Thus, it doesn''t make sense for a pinned object to be garbage
collectible. The object can''t be considered garbage anyway while
you''re still holding a reference to it, and once you let go of the
last reference, it''s no longer pinned.


我不明白为什么你甚至希望它实际上是收藏品。

固定点是让非托管代码访问对象,而不用担心GC会移动它。但是收集这个对象并让它的内存被用于其他东西就像移动它一样危险!
I don''t see why you''d even want it to be collectible, actually. The
point of pinning is to let unmanaged code access the object without
worrying that the GC will move it. But collecting the object and
letting its memory be used for something else is just as dangerous as
moving it!



你混合两点:


- 对无记忆记忆的引用,这个词也固定在

意味着它不会被收集。

- 数组在GC中的位置(堆或其他)。


当阵列是固定它被复制到堆。所有我想要看到的是
最初是在堆上分配数组的选项。


一旦数组超过<,就会在堆上自动分配数组br />
a一定的大小和周四'变成'固定',因为堆是从未压缩的所有地址都是绝对的。


You are mixing two points:

- reference to unamanged memory, where the word pinned also
means that it won''t be collected.
- location of the array in GC (Heap or else).

When the array is pinned it is copied to heap. All I would like
to see is an option to allocate the array on the heap initially.

The array is automatically allocated on the heap once it exceeds
a certain size and thu''s becomes "pinned", because the heap is
never compacted and all addresses are absolute.



真的吗?我认为数组总是在堆上分配,就像任何

其他引用类型一样。为什么你说堆永远不会被压缩?


Jesse

Really? I thought arrays were always allocated on the heap, like any
other reference type. And why do you say the heap is never compacted?

Jesse


嗨!

虽然复制在哪里?固定并不固有

涉及复制。
Where is that copying taking place though? Pinning doesn''t inherently
involve copying.



是的。确实如此。短于限制的所有阵列都在可压缩的内部分配。 GC堆的一部分因此必须从可压缩的中复制

。在他们可以拥有固定之前堆地址。


谢谢!

Atmapuri

Yes. It does. All arrays shorter than the limit are allocated inside
the "compactable" part of the GC heap and thus have to be copied
out of the "compactable" heap before they can have a "fixed" address.

Thanks!
Atmapuri


这篇关于垃圾收集固定阵列!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆