How to do a function pointer to "malloc" and "free"?

Adam Ruppe destructionator at gmail.com
Mon Oct 18 00:51:58 UTC 2021


On Sunday, 17 October 2021 at 23:07:15 UTC, Elmar wrote:
> Do you have a link for more information how to initialize the D 
> runtime?

Export a function that calls this:
http://druntime.dpldocs.info/core.runtime.Runtime.initialize.html

And also export a function that calls this:
http://druntime.dpldocs.info/core.runtime.Runtime.terminate.html

And tell the user to call those when they load/unload the 
library. (It is pretty common for C libraries to require explicit 
init/term calls so they should be used to it.)

They refcount internally so it is ok to call multiple times, just 
make sure the init and term are always paired.



(btw the druntime actually exports them as extern(C) 
rt_init/rt_term but I'd still recommend you do your own anyway. 
if you do have extra work to do you can just do it there, and it 
can use whatever your lib naming conventions are. and besides im 
not sure if the extern(C) things are specified stable (even 
though they have been for as long as i can remember), whereas 
doing your own thing that `import core.runtime; return 
Runtime.initalize;` is. )


More information about the Digitalmars-d-learn mailing list