Search code examples
d

Is there additional overhead in using D instead of C if I'm writing code to extend interpreted languages?


Maybe D runtime/GC has to initialize and go away every time a function is called, in a way that would not make it useful for adding small do-very-little functions like string to lower, urlencode etc. I'm not sure how this works yet but I've written a few extensions in C.


Solution

  • Yes, the D runtime has to initialise when the D program starts, and (depending on what libraries you use) static constructors need to be called. It's minimal, but like you said, it would be inefficient for small functions.

    The druntime is open source. Here's druntime's main function.

    If you are just exporting functions through a C interface (using extern(C)) and calling those then there is no need to start up the runtime, although you shouldn't use the GC or rely on static constructors etc. if you do that.