Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Thursday, 19 August 2021 at 15:38:19 UTC, evilrat wrote: On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş Btw, based on https://github.com/dlang/druntime/blob/master/src/object.d#L4209: import core.lifetime; import core.stdc.stdio; import core.stdc.stdlib; extern (C) void

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Thursday, 19 August 2021 at 15:38:19 UTC, evilrat wrote: On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş This is cool, but even in unit tests for malloc wrapper there is only simple case with class without references to another class and no dtor. If you examine the entire

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Tejas via Digitalmars-d-learn
On Thursday, 19 August 2021 at 09:39:26 UTC, evilrat wrote: On Thursday, 19 August 2021 at 08:25:23 UTC, Bienlein wrote: Oops, I just realized that you can also not call emplace when @nogc is present. Well that is at least consistent with not either being able to call destroy ;-). So, I

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread evilrat via Digitalmars-d-learn
On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş wrote: On Thursday, 19 August 2021 at 07:30:38 UTC, Bienlein wrote: Hello, I allocate some instance of class C manually and then free the memory again: [...] I just wanted to leave this here.

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Thursday, 19 August 2021 at 07:30:38 UTC, Bienlein wrote: Hello, I allocate some instance of class C manually and then free the memory again: [...] I just wanted to leave this here. https://github.com/AuburnSounds/Dplug/blob/master/core/dplug/core/nogc.d

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Bienlein via Digitalmars-d-learn
This works, vit. Thanks! I thought it wouldn't, because your code still makes use of embrace. But it somehow worked, although I don't understand why ... ;-). I also added a constructor using the same approach as your destructor and this also worked: this(int otherNum) @nogc {

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread evilrat via Digitalmars-d-learn
On Thursday, 19 August 2021 at 08:25:23 UTC, Bienlein wrote: Oops, I just realized that you can also not call emplace when @nogc is present. Well that is at least consistent with not either being able to call destroy ;-). So, I guess this means that you can forget about manually allocating

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread vit via Digitalmars-d-learn
On Thursday, 19 August 2021 at 08:25:23 UTC, Bienlein wrote: On Thursday, 19 August 2021 at 07:30:38 UTC, Bienlein wrote: Hello, I allocate some instance of class C manually and then free the memory again: class C { int num; ~this() { writeln("~this"); }

Re: How to call destructor before free without dropping @nogc?

2021-08-19 Thread Bienlein via Digitalmars-d-learn
On Thursday, 19 August 2021 at 07:30:38 UTC, Bienlein wrote: Hello, I allocate some instance of class C manually and then free the memory again: class C { int num; ~this() { writeln("~this"); } } void foo() // @nogc { auto mem =

How to call destructor before free without dropping @nogc?

2021-08-19 Thread Bienlein via Digitalmars-d-learn
Hello, I allocate some instance of class C manually and then free the memory again: class C { int num; ~this() { writeln("~this"); } } void foo() // @nogc { auto mem = cast(C)malloc(__traits(classInstanceSize, C)); auto c =