www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [D1] gc safety

reply %u <e ee.com> writes:
How gc unfriendly is an union of objects and sizet_t?

union{
  size_t arr[10];
  Class obj[10];
}


And, if multiple arrays contain exclusively the same objects, is it then
safe/useful to mark all but the smallest array with gc.hasNoPointers?
Any object removal/addition happens simultaneous across all the arrays.

void remove(size_t i){
  size_t i2 = arr[i].i2;
  arr2[i2] = null;
  arr[i] = null;
}

ps. I was tempted to make the subject "[D1,gc(safety),union]"..
Oct 10 2010
next sibling parent %u <e ee.com> writes:
Please tell me if anything is unclear/stupid :)

== Quote from %u (e ee.com)'s article
 How gc unfriendly is an union of objects and sizet_t?
 union{
   size_t arr[10];
   Class obj[10];
 }
 And, if multiple arrays contain exclusively the same objects, is it then
 safe/useful to mark all but the smallest array with gc.hasNoPointers?
 Any object removal/addition happens simultaneous across all the arrays.
 void remove(size_t i){
   size_t i2 = arr[i].i2;
   arr2[i2] = null;
   arr[i] = null;
 }
Oct 12 2010
prev sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
%u <e ee.com> wrote:

 How gc unfriendly is an union of objects and sizet_t?

 union{
   size_t arr[10];
   Class obj[10];
 }
All elements of this union will be considered pointers by the GC.
 And, if multiple arrays contain exclusively the same objects, is it then
 safe/useful to mark all but the smallest array with gc.hasNoPointers?
 Any object removal/addition happens simultaneous across all the arrays.
As long as there is at least one GC registered pointer to the allocated objects, it will not be collected. Hence, if some arrays are permutations or subsets of another array, only the original array need to be marked as having pointers. -- Simen
Oct 12 2010
parent reply %u <e ee.com> writes:
== Quote from Simen kjaeraas (simen.kjaras gmail.com)'s article
 %u <e ee.com> wrote:
 How gc unfriendly is an union of objects and sizet_t?

 union{
   size_t arr[10];
   Class obj[10];
 }
All elements of this union will be considered pointers by the GC.
The object will always occupy a continuous obj[0..x], is there some way to explain this to the GC?
 And, if multiple arrays contain exclusively the same objects, is it then
 safe/useful to mark all but the smallest array with gc.hasNoPointers?
 Any object removal/addition happens simultaneous across all the arrays.
As long as there is at least one GC registered pointer to the allocated objects, it will not be collected. Hence, if some arrays are permutations or subsets of another array, only the original array need to be marked as having pointers.
Thanks :) The GC will probably really like this as one of the arrays is cubed the size of the smallest one :D
Oct 12 2010
parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
%u <e ee.com> wrote:

 == Quote from Simen kjaeraas (simen.kjaras gmail.com)'s article
 %u <e ee.com> wrote:
 How gc unfriendly is an union of objects and sizet_t?

 union{
   size_t arr[10];
   Class obj[10];
 }
All elements of this union will be considered pointers by the GC.
The object will always occupy a continuous obj[0..x], is there some way to explain this to the GC?
Perhaps. Is there a way to explain it to me? Do you mean the first x elements will be objects, and the rest will be size_ts that are not pointers? -- Simen
Oct 12 2010
parent reply %u <e ee.com> writes:
== Quote from Simen kjaeraas (simen.kjaras gmail.com)'s article
 %u <e ee.com> wrote:
 == Quote from Simen kjaeraas (simen.kjaras gmail.com)'s article
 %u <e ee.com> wrote:
 How gc unfriendly is an union of objects and sizet_t?

 union{
   size_t arr[10];
   Class obj[10];
 }
All elements of this union will be considered pointers by the GC.
The object will always occupy a continuous obj[0..x], is there some way to explain this to the GC?
Perhaps. Is there a way to explain it to me? Do you mean the first x elements will be objects, and the rest will be size_ts that are not pointers?
Exactly that.
Oct 13 2010
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
%u <e ee.com> wrote:

 Perhaps. Is there a way to explain it to me? Do you mean the first x
 elements will be objects, and the rest will be size_ts that are not
 pointers?
Exactly that.
No. The GC only cares about whole blocks, not singular locations within each. That said, there is a bug report with a GC that uses precise scanning (http://d.puremagic.com/issues/show_bug.cgi?id=3463). As you are using D1, I believe it should work for you. -- Simen
Oct 13 2010