![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
When gc-able objects are created, this happens at increasing (or decreasing) addresses. Is the ordering of these addresses guaranteed to stay the same? Or can an object be moved past another during compacting, as a result of pinning or gc optimization techniques? A scenario might look like: create objects A-P create Q create R create S forget A-P pin Q gc while Q pinned unpin Q When compacting, will R and S be moved before P? Say, R is large and can't be fitted before Q. Will S then be moved to fill the vacant space? I ask this because I need an ordering of objects for a project. The ordering does not need to be immune to serialization/deserialization, but it must be immune to garbage collection. The objects aren't going to be pinned by my code but other pinned objects might exist. Is it possible in verifiable code to compare the pointers? |
#3
| |||
| |||
|
|
"Ole Nielsby" <ole.nielsby (AT) snailmail (DOT) dk> wrote: When gc-able objects are created, this happens at increasing (or decreasing) addresses. Is the ordering of these addresses guaranteed to stay the same? [...] I'm not 100% about the order changing. but I don't think anything is guarenteed. My question is what could you possibly be writing that requires knowing the order of objects? |
#4
| |||
| |||
|
|
When gc-able objects are created, this happens at increasing (or decreasing) addresses. Is the ordering of these addresses guaranteed to stay the same? Or can an object be moved past another during compacting, as a result of pinning or gc optimization techniques? A scenario might look like: create objects A-P create Q create R create S forget A-P pin Q gc while Q pinned unpin Q When compacting, will R and S be moved before P? Say, R is large and can't be fitted before Q. Will S then be moved to fill the vacant space? I ask this because I need an ordering of objects for a project. The ordering does not need to be immune to serialization/deserialization, but it must be immune to garbage collection. The objects aren't going to be pinned by my code but other pinned objects might exist. Is it possible in verifiable code to compare the pointers? Thanks/Ole N: |
#5
| |||
| |||
|
|
Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote: "Ole Nielsby" <ole.nielsby (AT) snailmail (DOT) dk> wrote: When gc-able objects are created, this happens at increasing (or decreasing) addresses. Is the ordering of these addresses guaranteed to stay the same? [...] I'm not 100% about the order changing. but I don't think anything is guarenteed. My question is what could you possibly be writing that requires knowing the order of objects? I'm dealing with attribute lists. I need to sort the attribute names (which are unified constants of various types, including tuples of other constants) in an arbitrary but consistent order. Simply using the addresses would give a very fast sort. Why sort it then? Wouldn't just creating htem and inserting them into a list |
#6
| |||
| |||
|
|
"Ole Nielsby" <ole.nielsby (AT) snailmail (DOT) dk> wrote in message I'm dealing with attribute lists. I need to sort the attribute names (which are unified constants of various types, including tuples of other constants) in an arbitrary but consistent order. Simply using the addresses would give a very fast sort. Why sort it then? Wouldn't just creating them and inserting them into a list achieve the same thing? |
#7
| |||
| |||
|
|
Compaction is not ever going to change the order of objects on the managed heap. Free blocks are going to show as System.Free on the managed heap until they are returned to the OS. The only exception to that is the LOH which will never return free blocks. On the LOH, we will reuse free blocks as needed. |
#8
| |||
| |||
|
|
Is this behaviour part of the clr specification, or is there a risk that future or alternative versions of the clr (Mono etc.) might break it - or is there a silent agreement not to break it? I can't find a method for pointer comparison in the class library (except ReferenceEquals which doesn't provide an ordering). Is this because I haven't looked in the right place or because I'm not supposed to rely on pointer order? I might be able to convert the pointers to IntPtrs, but there will still be a race condition: what if a gc happens between the two casts? |
#9
| |||
| |||
|
|
Don't ever design your app with a reliance upon any particular implementation. You never know about changes. |
|
Fact is, you can never know where an object is without walking the roots. That's why we have pinning. |
#10
| |||
| |||
|
|
Jim Cheshire <contactme (AT) mysite (DOT) com> wrote: Fact is, you can never know where an object is without walking the roots. That's why we have pinning. I've been involved with compacting garbage collectors long before the clr was born (I implemented one on a Z80 CMP system back in 1985), so it's not like those walking pointers are aliens. |

![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |