> You've probably hit a corner case for the garbage collector.  When you 
> allocate
> 20,000,000 Object instances and hold onto the references, the garbage 
> collector
> probably runs about a zillion times and never finds anything to delete.  If 
> this
> is a bottleneck, you should temporarily disable the garbage collector in these
> situations, until you are done with all these allocations, then re-enable it.

Thanks.  Disble gc improve the speed by 5x:

$ dmd -O -release allocd.d
$ time ./allocd
real    0m4.080s
user    0m3.644s
sys     0m0.420s


$ cat allocd.d
import core.memory;

int main() {
  core.memory.GC.disable();
  int i, n = 20000000;
  Object[] oa;
  oa = new Object[n];
  for (i = n; i-- > 0; ) {
    oa[i] = new Object();
  }
  core.memory.GC.enable();

  return 0;
}

Reply via email to