-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposing fftw_clone()
to allow memory-safe C++ wrappers
#106
Comments
This seems reasonable to me, and should be relatively easy to implement, in principle: just create a plan for the same problem as the one stored in the plan (but with new pointers) using the Annoyances that immediately occur to me:
|
It would be even easier, and probably more reasonable, to just define (You'd still need a deep-copy method to clone the |
Thanks for the info, @stevengj! fftw_plan fftw_clone(const fftw_plan blueprint); |
(Probably it should be called |
Was this ever implemented? It would be very nice! |
Was never implemented as far as I know. A PR would be welcome. |
A potential implementation is in #314. |
One problem when using FFTW in non-trivial C++ applications is memory safety. This is particularly the case if an FFTW plan is embedded as a field in a class that should be copy-constructible and assignable:
As far as I can tell, there is no way to clone, i.e. to obtain a deep copy, of a plan, which is a problem in the copy constructor (and the assignment operator). An immediate workaround is to re-create the plan in the new object and copy all the data from the arrays. However, since
fftw_plan
is an opaque pointer, there is no portable way to recreate the plan from itself, which means the above snippet has to re-implemented for every use case.I therefore propose to add the following function (or something similar) to the public API:
This would immediately allow to write a copy-constructable wrapper class around a generic
fftw_plan
.If this proposal is accepted, I can help with the implementation, but I would need some pointers :)
The text was updated successfully, but these errors were encountered: