Hello, folks! Newbie to D, have some questions!
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 19 04:45:49 PST 2017
timmyjose wrote:
> a). So the GC is part of the runtime even if we specify @nogc
yes. GC is basically just a set of functions and some supporting data
structures, it is compiled in druntime. @nogc doesn't turn it off, if
says that compiler must ensure that *your* *code* doesn't allocate, at
compile time. i.e. @nogc code with GC allocations won't compile at all.
> b). Do we manually trigger the GC (like Java's System.gc(), even
> though that's not guaranteed), or does it get triggered automatically
> when we invoke some operations on heap allocated data and/or when the
> data go out of scope?
GC can be invoked *only* on allocation. as long as you don't allocate
GC data, GC will not be called. of course, things like array/string
concatenation (and closure creation) allocates, so you'd better be
careful with your code if you want to avoid GC in some critical part.
or you can call `GC.disable()` to completely disable GC (and
`GC.enable()` later, of course ;-).
> c). Does Rust have analogues of "new" and "delete", or does it use
> something like smart pointers by default?
`new`. no `delete`, tho, as it is not necessary with GC. actually,
there is `delete` thingy, but it is deprecated, and you'd better not
use it unless you are *really* know what you're doing and why. i.e.
don't prematurely optimize your code, especially without good
understanding of D's GC.
> Fascinating reading about the various use cases that you and others
> have put D to. It does give me a lot more contextual understanding
> now. Thank you!
you're welcome.
as for me, i am using D exclusively for *all* my programming tasks
(including writing simple shell scripts ;-) for years. and i don't want
to go back to C/C++ or switch to some [new] hyped language. i have 20+
years of programming expirience, and i feel that D is the best language
i ever used. don't get me wrong, tho: it doesn't mean that D is the
best language on the planet. what i mean is that D has a best balance
of features, warts, libs and so on *for* *me*. easy C interop allows me
to use all the C libraries out there; C-like syntax allows me to port C
code (i did alot of C ports, including NanoVG, NanoSVG, Tremor Vorbis
decoder, Opus decoder, etc.); great metaprogramming (for C-like
language) allows me to skip writing boilerplate code; and so on. ;-)
also, dmd compiler is easily hackable. trying to even compile gcc is a
PITA, for example. and dmd+druntime+phobos takes ~1.5 minutes to build
on my old i3.
More information about the Digitalmars-d-learn
mailing list