-
Notifications
You must be signed in to change notification settings - Fork 265
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
Make RtMidi moveable and non-copyable #238
Conversation
^^^ c++11 wasn't mandated by the CMakeLists.txt, and it's not immediately clear to me that it's required, so I included a macro for |
Just curious, what is the motivation to support C++03? 18 years ago... |
It doesn't matter to me, I only use c++11 and up. It just seemed a little presumptuous of me to come in here and introduce a new rule as part of my changes when it could be avoided. |
I tested this and it works. The main question I have is what happens to the moved object? You still have an RtMidiOut/In object after the move, but it no longer has a valid internal I played around with replacing I also found that replacing it with |
In the meantime this code was merged in #255, where I removed the backwards compatibility with C++98 in favor of just requiring C++11. So closing this, but please add any comments you might have on std::shared_ptr. (Changing it would not affect the API except to allow copy properly.) I suppose although it works, in principle the RtMidi objects represent unique instances of a device so it doesn't really make sense to support copy, although it is just a handle to an internal data structure. The shared_ptr has some small reference counting overhead that is maybe not justified? Although that's probably negligible. |
Exactly. |
Make
RtMidi
,RtMidiIn
, andRtMidiOut
moveable, but non-copyable.This was branched off of #237 -- Make RtMidi non-copyable.
Essentially I was trying to make a resizable
std::vector<RtMidiIn>
, but it didn't work as expected. Resizingstd::vector
requires copying or moving data when the internal array resizes, butRtMidi
's copy was not well-defined and ultimately caused the new RtMidi instances to have a dangling pointer to deleted memory (rtapi_
).Copying an
RtMidi
doesn't make sense at the moment because it will always destroy itsrtapi_
when it destructs, so twoRtMidi
instances sharing theirrtapi_
will always result in an error. For this reason I made it non-copyable.It was pointed out in #237 that making
RtMidi
moveable could still allow it to be used withstd::vector
. It also shouldn't cause any error conditions. So I implemented a move constructor forRtMidi
and its derived classes.Tested and working in Windows.