dustinlacewell / vcv-minilab3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In the future, consider using modern managed pointers.

squinkylabs opened this issue · comments

This code uses all "naked" pointers. The potential problem with this is that you forget to delete them, or you forget to initialize them. Or you shared objects ownership between multiple objects.

// so now you do
 router = new MidiRouter(0);

// you could instead do:
std::shared_ptr<MidiRouter> router;
router = std::make_shared<MidiRouter>();
// or use std::unique_ptr<T>

I wouldn't change all your code right now, but it's something to think about in the fugure.

Of course many Rack APIs will give you a pointer to something, but you don't own it, so you would not want to use one of these kinds of pointers, in effect messing up memory ownership>

This is a great idea. I studied the smart pointers quite a bit before getting started but didn't have the confidence to put them to use. I'll keep this one open because it's worth doing at some point.

I usually use std::shared_ptr for everything. Some ppl who really care about the last drop of efficiency use std::unique_ptr. unique_ptr is what you are supposed to use if there is only one client that needs to point to an object. But it's slightly more difficult to use (for me, anyway).