October 03, 2022

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

October 04, 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

1 2
Next ›   Last »