Using onOutOfMemoryError in C wrappers
Basile B.
b2.temp at gmx.com
Wed Mar 24 10:25:21 UTC 2021
On Wednesday, 24 March 2021 at 08:51:34 UTC, Per Nordlöw wrote:
> On Wednesday, 24 March 2021 at 08:31:19 UTC, Basile B. wrote:
>> There are several ways to do that. In addition to
>> onOutOfMemoryError, you can use a static instance
>>
>> void v() @nogc nothrow
>> {
>> __gshared oom = new OutOfMemoryError();
>> auto X* = X_create();
>> if (X is null)
>> throw oom;
>> }
>
> How is that better than
>
> void v() @nogc nothrow
> {
> auto X* = X_create();
> if (X is null)
> onOutOfMemoryError();
> }
>
> considering the fact that accessing `__gshared` state is
> neither `@safe` nor `pure`? Which, in turn, makes `v()`
> unconditionally unsafe and unpure regardless of safety and
> purity of `X_create()`.
In now way. But in your question you mentioned @nogc nothrow and
not @safe and pure.
More information about the Digitalmars-d-learn
mailing list