question about the garbage collector
Daniel Keep
daniel.keep.lists at gmail.com
Sun Mar 4 16:56:05 PST 2007
doob wrote:
> Jarrett Billingsley Wrote:
>
>> "Sean Kelly" <sean at f4.ca> wrote in message
>> news:esesnv$di1$1 at digitalmars.com...
>>
>>> You only need to do this if you're creating a D dynamic library, because
>>> in that case the default startup process is not executed and the GC is
>>> therefore not initialized.
>> You can also do it for regular Windows programs (i.e. in your WinMain), but
>> in that case you can also just use the standard D "int/void main()" and use
>> some Windows API functions to get the values which are usually passed as
>> parameters to WinMain. This way you don't have to do the D initialization
>> crap; D will handle that for you.
>>
>>
>
> So you're saying that if I want to create a regular windows program I don't need to initialize the garbage collector because it will do that by default and it will handle the C stuff also?
D's garbage collector only applies to things that are allocated via the
'new' keyword in D code*. C typically uses malloc, which the D garbage
collector can't even see, much less mess with. If you use malloc and
free from D code, then what you allocate using malloc won't be garbage
collected, either.
As for initialising it, I think this is what they're saying:
+) If you write your own WinMain function, you need to handle
initialising and shutting down the D runtime stuff like the GC, unit
tests, module ctors, etc.
+) If your program begins with a main function, on the other hand, you
don't need to worry about doing the setup manually, since D will have
handled it for you. You just need to figure out a way to get the
information that's usually passed to WinMain in some other manner.
Hope this helps.
-- Daniel
* Of course, this doesn't apply if you happen to override a particular
class' new and delete methods, but you hopefully won't be doing *that*
unless you already know how the GC works :P
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list