Stop writeln from calling object destructor
data pulverizer
data.pulverizer at gmail.com
Tue Oct 4 18:51:07 UTC 2022
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 working
>> with objects that have memory management external to D.
>
> I know you already solved the problem, but just for future
> reference, if you use something like `RefCounted`, you can
> avoid copying and destruction until everyone is done with the
> object. This is how my io library works, the IO objects are
> non-copyable, and you wrap them in `RefCounted` if you want to
> copy them.
>
> -Steve
Just seen this. Nice one. The docs link:
https://dlang.org/library/std/typecons/ref_counted.html
More information about the Digitalmars-d-learn
mailing list