Potential strategy for avoiding problems with copy of a struct (maybe??)

james.p.leblanc james.p.leblanc at gmail.com
Sun Aug 22 14:40:29 UTC 2021


On Sunday, 22 August 2021 at 13:37:50 UTC, jfondren wrote:

>     this(this) {
>         unique = null;
>     }
>
>     ~this() {
>         pureFree(unique);
>     }
> }

Dear jfondren,

I truly appreciate you taking the time to help me with my 
question!

**This bit of magic with the postblit may hold the key to my 
issue.**

(I have done some experiments based on your example code, am 
learning much,
and it looks VERY encouraging!

It is a bit scary how you guessed very closely what I am trying to
do.  I have a AVX aligned pointers (obtained from fftw_malloc), 
that I
want to protect.

To be a bit more specific.  The code that reads/writes from 
to/from fftw
routines is all pointer based.  But, to allow use of standard 
dlang things
such as "foreach" and friends, I've been cobbling together a 
(naive) wrapper.

This allows me to use standard dlang syntax and operator 
overloads.  I call my
struct "fakeArray" ... since it is meant to behave either as a 
static array,
or a dynamic array as needed.

It **seems** to work pretty well ... but protecting the arrays 
from accidental
programming mistakes (such as the "auto y=x") has been eluding me.

In fact, I **can** do a legitimate data copy via "y = x", as long 
as
y is already instantiated as a "fakeArray".

I must steady more the example you kindly provided (learn more 
about the
postblit, and pureFree, the const report function,  etc...)

Best Regards,
James








More information about the Digitalmars-d-learn mailing list