Re: struct destructor

2021-05-20 Thread Imperatorn via Digitalmars-d-learn
On Sunday, 16 May 2021 at 11:42:19 UTC, Adam D. Ruppe wrote: On Sunday, 16 May 2021 at 08:04:06 UTC, cc wrote: [...] destroy + GC.free has a quirk - GC.free only works on what GC.malloc returns, a base pointer, NOT what `new` returns. The documentation says this but it is a subtle detail eas

Re: struct destructor

2021-05-20 Thread frame via Digitalmars-d-learn
On Sunday, 16 May 2021 at 11:42:19 UTC, Adam D. Ruppe wrote: On Sunday, 16 May 2021 at 08:04:06 UTC, cc wrote: I tracked down the problem but wasn't 100% sure about the fix. Adding the GC.baseOf thing works for me but i didn't upstream since idk if it works for everyone else. maybe i should

Re: struct destructor

2021-05-16 Thread mw via Digitalmars-d-learn
On Sunday, 16 May 2021 at 11:42:19 UTC, Adam D. Ruppe wrote: On Sunday, 16 May 2021 at 08:04:06 UTC, cc wrote: If the goal is to absolutely squeeze the GC back down after using new or dynamic arrays, I find destroy + GC.free often fails to do the trick (e.g. GC.stats.usedSize remains high). d

Re: struct destructor

2021-05-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 16 May 2021 at 08:04:06 UTC, cc wrote: If the goal is to absolutely squeeze the GC back down after using new or dynamic arrays, I find destroy + GC.free often fails to do the trick (e.g. GC.stats.usedSize remains high). destroy + GC.free has a quirk - GC.free only works on what GC.

Re: struct destructor

2021-05-16 Thread cc via Digitalmars-d-learn
On Saturday, 15 May 2021 at 18:24:19 UTC, Alain De Vos wrote: Thanks, good idea but, It does not initiate a GC cycle or free any GC memory. Personally I wish D would re-implement "delete" and make it "just work" like one would assume, but from what I've seen there have been many many debates

Re: struct destructor

2021-05-15 Thread mw via Digitalmars-d-learn
On Saturday, 15 May 2021 at 18:26:08 UTC, Adam D. Ruppe wrote: On Saturday, 15 May 2021 at 17:55:17 UTC, Alain De Vos wrote: Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation. You're best off doing malloc+free if

Re: struct destructor

2021-05-15 Thread Alain De Vos via Digitalmars-d-learn
I'll try first the first tip of Adam, here the code, ``` import std.stdio:writeln; import core.memory: GC; void myfun(){ class C{ int[1] x; }//class C struct S { C c=null; @disable this(); this(int dummy) { c=new C();

Re: struct destructor

2021-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 May 2021 at 17:55:17 UTC, Alain De Vos wrote: Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation. You're best off doing malloc+free if you want complete control though.

Re: struct destructor

2021-05-15 Thread Alain De Vos via Digitalmars-d-learn
Sorry free does , indeed.

Re: struct destructor

2021-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 May 2021 at 18:15:24 UTC, Dennis wrote: On Saturday, 15 May 2021 at 17:55:17 UTC, Alain De Vos wrote: Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation. You can use [object.destroy](https://dlang.

Re: struct destructor

2021-05-15 Thread Alain De Vos via Digitalmars-d-learn
Thanks, good idea but, It does not initiate a GC cycle or free any GC memory.

Re: struct destructor

2021-05-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 May 2021 at 17:55:17 UTC, Alain De Vos wrote: Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation. You can use [object.destroy](https://dlang.org/phobos/object.html#.destroy) to destruct, and [GC.f

Re: struct destructor

2021-05-15 Thread Alain De Vos via Digitalmars-d-learn
Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation.

Re: struct destructor

2021-05-15 Thread Alain De Vos via Digitalmars-d-learn
On Saturday, 15 May 2021 at 16:53:04 UTC, Adam D. Ruppe wrote: On Saturday, 15 May 2021 at 16:52:10 UTC, Alain De Vos wrote: When I do a "new" in a struct constructor to assign to a member variable of this struct, what do i write in the same struct destructor to free the memory ? If you use

Re: struct destructor

2021-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 May 2021 at 16:52:10 UTC, Alain De Vos wrote: When I do a "new" in a struct constructor to assign to a member variable of this struct, what do i write in the same struct destructor to free the memory ? If you used `new` the garbage collector is responsible for it.

Re: Struct destructor

2019-03-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 2, 2019 4:32:53 AM MST JN via Digitalmars-d-learn wrote: > Compare this D code: > > import std.stdio; > > struct Foo > { > ~this() > { > writeln("Destroying foo"); > } > } > > void main() > { > Foo[string] foos; > > foos["bar"] = Foo(); > wr

Re: Struct destructor

2019-03-02 Thread Matheus via Digitalmars-d-learn
On Saturday, 2 March 2019 at 11:32:53 UTC, JN wrote: ... Is this proper behavior? I'd imagine that when doing foos.remove("bar"), Foo goes out of scope and should be immediately cleaned up rather than at the end of the scope? Or am I misunderstanding how should RAII work? https://dlang.org/s

Re: Struct destructor in a with block

2015-02-02 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 3 February 2015 at 05:09:55 UTC, Ali Çehreli wrote: Yes, it's a known bug that has been fixed on git head but I can't find the bug report. :-/ Ok cool, good to know. The new output: foo destoy Yes, without the 'r'. ;) Ali Yeah, i noticed the typo right after I posted...

Re: Struct destructor in a with block

2015-02-02 Thread Ali Çehreli via Digitalmars-d-learn
On 02/02/2015 07:51 PM, Tofu Ninja wrote: module main; import std.stdio; void main(string[] args) { with(test()) { foo(); } } struct test { void foo() { writeln("foo"); } ~this() { writeln("destoy"); } } prints: destro