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?

  • How to compile Phobos with ot... data pulverizer via Digitalmars-d-learn
    • Re: How to compile Phobo... kinke via Digitalmars-d-learn
      • Re: How to compile P... data pulverizer via Digitalmars-d-learn
        • Re: How to compi... Steven Schveighoffer via Digitalmars-d-learn
          • Re: How to c... data pulverizer via Digitalmars-d-learn
            • Re: How... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... data pulverizer via Digitalmars-d-learn
                • ... Adam D. Ruppe via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... data pulverizer via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... data pulverizer via Digitalmars-d-learn
                • ... bachmeier via Digitalmars-d-learn
                • ... data pulverizer via Digitalmars-d-learn
                • ... bachmeier via Digitalmars-d-learn
                • ... Alain De Vos via Digitalmars-d-learn
                • ... bachmeier via Digitalmars-d-learn

Reply via email to