View Single Post
Old 02-12-2017, 04:56 PM   #23
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by ceanganb View Post
Thanks for the into, Xenakios. C++ is still making sense to me, as I come from a procedural background. This OOP model is a struggle to a 43er
Well, to be honest, it is a mess in C++, since objects can be instantiated as values, as heap allocated objects stored in raw pointers, unique pointers or shared pointers etc...Every library/framework of course also has its own rules on what they prefer to use. However, the ability to do it in so many ways also gives flexibility that isn't necessarily available in other languages.

By the way, try to avoid doing manual "delete" calls on heap allocated objects. Manual deletes only leads to misery like double deletions and memory leaks. The example plugin breaks that rule because it would have been a bit contrived to use a smart pointer for the single Window object involved. Proper production code that uses multiple Window instances and creates/destroys them more dynamically should use some other solution. For example the Window instances could be stored in something like :

std::vector<std::shared_ptr<Window>> g_windows;

And then at plugin shutdown they could be destroyed by calling g_windows.clear();

I think I will change the example to do something like that... edit : I changed the window instance to use std::unique_ptr.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.

Last edited by Xenakios; 02-12-2017 at 05:32 PM.
Xenakios is offline   Reply With Quote