Re: Stop writeln from calling object destructor

2022-10-04 Thread data pulverizer via Digitalmars-d-learn
On Monday, 3 October 2022 at 11:08:00 UTC, Steven Schveighoffer wrote: On 10/2/22 12:21 PM, data pulverizer wrote: I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It has become a very serious problem when

Re: Stop writeln from calling object destructor

2022-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/2/22 12:21 PM, data pulverizer wrote: I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It has become a very serious problem when working with objects that have memory management external to D. I know you

Re: Stop writeln from calling object destructor

2022-10-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 October 2022 at 18:24:51 UTC, Ali Çehreli wrote: On 10/2/22 10:55, data pulverizer wrote: > ``` > this(T)(ref return scope T original) > if(is(T == RVector!(Type))) > { > //... code ... > } > ``` I've just tested. That is used only for explicit constructor syntax: auto

Re: Stop writeln from calling object destructor

2022-10-02 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 2 October 2022 at 18:24:51 UTC, Ali Çehreli wrote: I've just tested. That is used only for explicit constructor syntax ... Many thanks. Knowledgeable as always!

Re: Stop writeln from calling object destructor

2022-10-02 Thread Ali Çehreli via Digitalmars-d-learn
On 10/2/22 10:55, data pulverizer wrote: > On Sunday, 2 October 2022 at 17:28:51 UTC, data pulverizer wrote: >> Sorry I'll need to implement all the overloaded copy constructors and >> see if that fixes it. > > I've got it, something weird happened to my copy constructor. This was > my original

Re: Stop writeln from calling object destructor

2022-10-02 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 2 October 2022 at 17:51:59 UTC, Ali Çehreli wrote: What I noticed first in your original code was that it would be considered buggy because it was not considering copying. Every struct that does something in its destructor should either have post-blit (or copy constructor) defined

Re: Stop writeln from calling object destructor

2022-10-02 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 2 October 2022 at 17:28:51 UTC, data pulverizer wrote: Sorry I'll need to implement all the overloaded copy constructors and see if that fixes it. I've got it, something weird happened to my copy constructor. This was my original attempt and was ignored (didn't run in the copy

Re: Stop writeln from calling object destructor

2022-10-02 Thread Ali Çehreli via Digitalmars-d-learn
On 10/2/22 10:28, data pulverizer wrote: > On Sunday, 2 October 2022 at 17:19:55 UTC, data pulverizer wrote: >> Any reason why this could be? > What I noticed first in your original code was that it would be considered buggy because it was not considering copying. Every struct that does

Re: Stop writeln from calling object destructor

2022-10-02 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 2 October 2022 at 17:19:55 UTC, data pulverizer wrote: Any reason why this could be? Sorry I'll need to implement all the overloaded copy constructors and see if that fixes it.

Re: Stop writeln from calling object destructor

2022-10-02 Thread data pulverizer via Digitalmars-d-learn
On Sunday, 2 October 2022 at 16:44:25 UTC, Paul Backus wrote: It's because `writeln` is copying the object, and each of the copies is being destroyed. If you add a copy constructor to your example, you can see it happening: ... I thought something like this could be happening in my original

Re: Stop writeln from calling object destructor

2022-10-02 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 2 October 2022 at 16:21:47 UTC, data pulverizer wrote: I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It's because `writeln` is copying the object, and each of the copies is being destroyed. If

Stop writeln from calling object destructor

2022-10-02 Thread data pulverizer via Digitalmars-d-learn
I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It has become a very serious problem when working with objects that have memory management external to D. Here is a repeatable example, where the destructor