Class-related queries [was: Re: 'Undefined reference' linking errors]
Joseph Wakeling
joseph.wakeling at gmail.com
Fri Apr 9 07:33:37 PDT 2010
Thanks for the interesting and detailed explanation. :-)
> Now you see, 'new' is for dynamic memory allocation in D as well, it's
> just that for classes it is required. You normally don't need to worry
> about 'delete', as the GC will take care of deallocation.
I guess I am worried about what could happen in the case of code like this in C++:
for(i=0;i<10000;++i) {
Foo f(i);
// Do something with f ...
}
... when it reappears in D as:
foreach(uint i;0..10000) {
auto f = new Foo(i);
// Do something with f ...
}
Of course, it's not so terrible to have to put an explicit 'delete' statement at
the end of the foreach loop if that is necessary (I am after all a C person at
heart:-). It's also clear that GC will probably make such a loop more efficient
as it will manage the alloc/dealloc'ing of the memory more intelligently within
the system constraints. But the concern is there ...
More information about the Digitalmars-d-learn
mailing list