Raw pointers are going to give you a headache unless you rigorously manage them yourself - not saying you wonât, but often, especially in complex multi-threaded applications, you can trip over them. Forget to de-allocate, forget the move/share semantic, etc. Subtle bugs can manifest with raw pointers - the kind that should have been dustbinâed decades ago. That said, use them if you really know what youâre doing. Most of the time, unique_ptr is a better choice, because scope is important in modern execution environments.
unique_ptrâs are a good âdefaultâ choice to use, because theyâre not reference counted and therefore donât have the overhead typically associated with shared_ptrâs, and you can be sure that only one object will âownâ the pointer at a time - since you may only std::move them when you expect to.
shared_ptrâs are useful when you only use them when you know you need to share them between execution units, and any allocâs associated with a shared_ptr will be tracked by the C++ runtime.
You use a unique_ptr in the processor, because this guarantees that only your processor object will have access to the objects referenced by them, ensuring the âuniquenessâ of accessing them during the life-cycle of your processing execution unit. In the context of audio processing, you really donât want the APVTStatesâ being modified out of context of the processing execution unit. You also donât want any overhead (shared_ptrâs have a slight âcostâ of reference counting) during the processing execution unit, since audio is performance-dependent.
Raw pointers are useful when you need access to something that you wonât manage - youâre not going to be responsible for allocating the data, you just want to access it - to read values, and make âquickâ (non-reference counted) modifications in a âsafeâ unit of execution. If you donât âownâ the object referred to by the raw pointer, and are not âresponsibleâ for its alloc/de-alloc, and know that your execution unit will not be interrupted during the period of accessing the data behind the pointer, then raw pointers are fine to use.
In short, each pointer type has its uses. Its not a dumb question to ask âwhy?â - you should know, intuitively, why. If you donât feel like you understand it properly, its good to ask. As you proceed with larger and more sophisticated C++ projects, the good habits you pick up from the JUCE framework will serve you well âŠ