How to compile Phobos with other D code to create a shared library?
data pulverizer
data.pulverizer at gmail.com
Mon May 31 21:46:09 UTC 2021
On Monday, 31 May 2021 at 21:26:15 UTC, Steven Schveighoffer
wrote:
>
> You need to call it wherever you think it might not have been
> called yet.
>
> It's reentrant, so if you call it more than once, it will only
> initialize once, and count how many times you have to call
> `Runtime.terminate`.
>
> Best to use a `scope(exit)` to call `Runtime.terminate` if you
> are calling it periodically.
Many thanks!
Something interesting is using arrays. I can see that if you
instantiate an array within the D function using `new`, for
instance
```
auto result = new double[n];
```
you can't return that array to Julia (or whatever) if your
function does
```
scope(exit) Runtime.terminate();
```
and it segfaults. But while you can do:
```
auto result = cast(double*)malloc(double.sizeof * n);
```
you're left with the issue of not being able to free the memory
since you've terminated the runtime.
So I guess you have to appropriately pair up `initialize` and
`terminate` as appropriate to kind of *startup* and and
*shutdown* the connection with druntime with your allocations if
they stay within D?
More information about the Digitalmars-d-learn
mailing list